Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass usingattributes (http://www.velocityreviews.com/forums/t955396-re-announce-thesaurus-a-recursive-dictionary-subclass-usingattributes.html)

Mitya Sirenef 12-12-2012 12:53 AM

Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass usingattributes
 
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/...unch-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/1...nymous-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/



All times are GMT. The time now is 07:13 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.