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


Groups > comp.lang.python > #36443

ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <dave@cinege.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'python,': 0.02; 'else:': 0.03; 'example:': 0.03; 'output': 0.04; '"""': 0.05; '__name__': 0.07; 'attributes': 0.07; 'class,': 0.07; 'except:': 0.07; 'filename:fname piece:py': 0.07; 'indices': 0.07; 'main()': 0.07; 'nested': 0.07; 'try:': 0.07; 'ugly': 0.07; 'python': 0.09; "'''": 0.09; "'.'": 0.09; 'additionally': 0.09; 'called.': 0.09; 'exiting': 0.09; 'key)': 0.09; 'name)': 0.09; 'name):': 0.09; 'of)': 0.09; 'self.data': 0.09; 'subclass': 0.09; 'subject:using': 0.09; 'def': 0.10; 'read.': 0.13; "'__main__':": 0.16; '__version__': 0.16; 'attr': 0.16; 'dictionaries': 0.16; 'dictionary.': 0.16; 'from:addr:dave': 0.16; 'key):': 0.16; 'magic.': 0.16; 'programing': 0.16; 're-written': 0.16; 'recurse': 0.16; 'simple.': 0.16; 'import': 0.21; 'keys': 0.22; 'skip:% 10': 0.22; 'cc:2**0': 0.23; "i've": 0.23; 'raise': 0.24; 'external': 0.24; 'command': 0.24; 'allows': 0.25; 'creating': 0.26; 'cc:addr:gmail.com': 0.27; 'skip:# 10': 0.27; 'regular': 0.27; 'lines': 0.28; 'dictionary': 0.29; 'fighting': 0.29; 'statements': 0.29; 'str': 0.29; 'value)': 0.29; 'objects': 0.29; 'skip:_ 10': 0.29; 'class': 0.29; 'code': 0.31; "skip:' 20": 0.32; 'skip:- 10': 0.32; 'could': 0.32; 'print': 0.32; 'to:addr:python-list': 0.33; '(c)': 0.33; 'skip:d 20': 0.34; 'changed': 0.34; 'self': 0.34; 'but': 0.36; 'charset:us-ascii': 0.36; 'subject:: ': 0.38; 'easier': 0.38; 'object': 0.38; 'skip:l 20': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'easily': 0.39; 'notice': 0.39; 'space': 0.39; 'called': 0.39; 'your': 0.60; 'easy': 0.60; 'you.': 0.61; 'real': 0.61; 'header:Message-Id:1': 0.62; 'different': 0.63; 'more': 0.63; 'wish': 0.70; 'programs,': 0.71; 'realized': 0.71; 'walk': 0.71; 'yourself': 0.77; "'class'": 0.84; 'locals': 0.84; 'often,': 0.84
To python-list@python.org
Subject ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes
From Dave Cinege <dave@cinege.com>
Date Tue, 8 Jan 2013 12:02:33 -0500
MIME-Version 1.0
Content-Type Multipart/Mixed; boundary="Boundary-00=_pEF7Qa1xdxrjXPU"
Cc "Martin W. Capdevielle" <xaqshunr@gmail.com>
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.284.1357665177.2939.python-list@python.org> (permalink)
Lines 136
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1357665177 news.xs4all.nl 6961 [2001:888:2000:d::a6]:52952
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:36443

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

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.

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


Thread

ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes Dave Cinege <dave@cinege.com> - 2013-01-08 12:02 -0500
  Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes Duncan Booth <duncan.booth@invalid.invalid> - 2013-01-10 11:34 +0000
    Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes 88888 Dihedral <dihedral88888@googlemail.com> - 2013-01-10 05:04 -0800

csiph-web