Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #34610

Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <prvs=685ef806a=jeanmichel@sequans.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'output': 0.04; 'attributes': 0.07; 'class,': 0.07; 'nested': 0.07; 'additionally': 0.09; 'called.': 0.09; 'exiting': 0.09; 'of)': 0.09; 'subclass': 0.09; 'subject:using': 0.09; 'cc:addr:python- list': 0.10; 'read.': 0.13; 'dictionaries': 0.16; 'dictionary.': 0.16; 'programing': 0.16; 're-written': 0.16; 'simple.': 0.16; 'subject: \n ': 0.16; 'why,': 0.16; 'keys': 0.22; 'cc:2**0': 0.23; "i've": 0.23; 'cc:no real name:2**0': 0.24; 'external': 0.24; 'command': 0.24; 'allows': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'lines': 0.28; 'dictionary': 0.29; 'fighting': 0.29; 'url:mailman': 0.29; 'objects': 0.29; 'class': 0.29; "i'm": 0.29; 'code': 0.31; 'url:python': 0.32; '-----': 0.32; 'could': 0.32; 'print': 0.32; 'url:listinfo': 0.32; 'changed': 0.34; 'url:org': 0.36; 'thank': 0.36; 'subject:: ': 0.38; 'store': 0.38; 'easier': 0.38; 'some': 0.38; 'sure': 0.38; 'notice': 0.39; 'url:mail': 0.40; 'you.': 0.61; 'received:194': 0.61; 'different': 0.63; 'information': 0.63; 'person,': 0.65; 'disclose': 0.69; 'wish': 0.70; 'notice:': 0.71; 'programs,': 0.71; 'realized': 0.71; 'privileged.': 0.72; 'yourself': 0.77; "'class'": 0.84; 'often,': 0.84; 'medium.': 0.91
X-IronPort-AV E=Sophos;i="4.84,258,1355094000"; d="scan'208";a="983168"
X-Virus-Scanned amavisd-new at zimbra.sequans.com
Date Tue, 11 Dec 2012 11:09:30 +0100 (CET)
From Jean-Michel Pichavant <jeanmichel@sequans.com>
To Dave Cinege <dave@cinege.com>
In-Reply-To <201212102248.50766.dave@cinege.com>
Subject Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes
MIME-Version 1.0
X-Mailer Zimbra 7.2.0_GA_2669 (ZimbraWebClient - GC7 (Linux)/7.2.0_GA_2669)
Content-Type text/plain; charset="utf-8"
Content-Transfer-Encoding base64
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.719.1355220546.29569.python-list@python.org> (permalink)
Lines 26
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1355220546 news.xs4all.nl 6962 [2001:888:2000:d::a6]:45249
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:34610

Show key headers only | View raw



----- Original Message -----
> Thesaurus: A different way to call a dictionary.
> 
> Thesaurus is a new a dictionary subclass which allows calling keys as
> if they are class attributes and will search through nested objects
> recursively when __getitem__ is called.
> 
> You will notice that the code is disgusting simple. However I have
> found that
> this has completely changed the way I program in python. I've
> re-written some
> exiting programs using Thesaurus, and often realized 15-30% code
> reduction.
> Additionally I find the new code much easier to read.
> 
> If you find yourself programing with nested dictionaries often,
> fighting to
> generate output or command lines for external programs, or wish you
> had
> a dictionary that could act (sort of) like a class, Thesaurus may be
> for you.
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 

did you know you can write

class TestClass:
	no = 'Class'
	way = 'this'


tc = TestClass()

print "Something you find clean, and I'm not sure why, this is way %(way)s and this is no %(no)s" % vars(tc).


JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-12-11 11:09 +0100

csiph-web