Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'anyway.': 0.04; 'python': 0.09; '2.3,': 0.09; 'python:': 0.09; 'solution,': 0.09; 'subclass': 0.09; 'subject:using': 0.09; 'url:activestate': 0.09; 'defaultdict': 0.16; 'it..': 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'recipe': 0.16; 'recipes': 0.16; 'statement.': 0.16; 'statements,': 0.16; 'wrote:': 0.17; '2.2': 0.17; 'alex': 0.17; 'pointed': 0.17; 'nearly': 0.23; 'this:': 0.23; "i've": 0.23; 'pass': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; '2.6': 0.27; 'url:code': 0.29; 'class': 0.29; "i'm": 0.29; 'usually': 0.30; 'initially': 0.30; 'code': 0.31; 'december': 0.32; 'running': 0.32; 'getting': 0.33; 'avoiding': 0.33; 'rid': 0.33; 'problem': 0.33; 'to:addr:python- list': 0.33; 'another': 0.33; "can't": 0.34; 'doing': 0.35; 'pm,': 0.35; 'sometimes': 0.35; 'but': 0.36; 'possible': 0.37; 'beyond': 0.37; 'uses': 0.37; 'subject:: ': 0.38; 'skip:o 20': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'called': 0.39; 'received:192.168': 0.40; 'think': 0.40; 'your': 0.60; 'ago.': 0.66; 'finally': 0.66; 'levels': 0.66; 'believe': 0.69; 'soon.': 0.73; 'dict,': 0.84; 'reminds': 0.84; 'dirty': 0.91; 'old.': 0.95 Date: Tue, 11 Dec 2012 19:53:25 -0500 From: Mitya Sirenef User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121011 Thunderbird/16.0.1 MIME-Version: 1.0 To: python-list@python.org Subject: Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes References: <201212102248.50766.dave@cinege.com> <201212111557.24851.dave@linkscape.net> <201212111739.12794.dave@cinege.com> In-Reply-To: <201212111739.12794.dave@cinege.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 58 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1355273616 news.xs4all.nl 6912 [2001:888:2000:d::a6]:36588 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:34668 On 12/11/2012 05:39 PM, Dave Cinege wrote: > On Tuesday 11 December 2012 16:53:12 Ian Kelly wrote: > >> Just out of curiosity, how old are we talking? enumerate was added in >> Python 2.3, which is nearly 10 years old. Prior to 2.2 I don't think >> it was even possible to subclass dict, which would make your Thesaurus >> implementation unusable, so are these systems running Python 2.2? > > I'm finally beyond 2.2 and getting rid of 2.4 soon. Just started using 2.6 5 > months ago. > > Thesaurus initially came about from me doing this: > class Global: > pass > g = Global() > > As a way to organize/consolidate global vars and eliminate the global > statement. I think that's the key issue here. I find that when code is well structured, you pretty much never have a need for global statements, anyway. By the way, the Thesaurus class reminds me of using the old recipe called 'Bunch': http://code.activestate.com/recipes/52308-the-simple-but-handy-collector-of-a-bunch-of-named/ like this: b = Bunch(x=1) b.stuff = Bunch(y=2) b.stuff.y 2 I've also seen an answer on StackOverflow that uses automatic recursive 'Bunching': http://stackoverflow.com/questions/1123000/does-python-have-anonymous-classes I've seen another variation of recursive bunching, I think it was by Alex Martelli on StackOverflow, but I can't find it now, I believe it used defaultdict as part of it.. This approach can be handy sometimes but has drawbacks, as others have pointed out. I think the issue is that it's not a "solution for avoiding globals", which is not a problem in need of solution, but this can be a quick and dirty way to organize a few levels of dicts/Bunches and usually people come up with a custom variation on these recipes that suit their program. -- Lark's Tongue Guide to Python: http://lightbird.net/larks/