Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass usingattributes

Reply
Thread Tools

Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass usingattributes

 
 
Mitya Sirenef
Guest
Posts: n/a
 
      12-12-2012
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/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass usingattributes Ian Kelly Python 0 12-11-2012 10:20 PM
Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass usingattributes Ian Kelly Python 0 12-11-2012 09:53 PM
Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass usingattributes Dave Cinege Python 0 12-11-2012 08:57 PM
Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass usingattributes Ian Kelly Python 0 12-11-2012 06:41 AM
Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass usingattributes Jason Friedman Python 0 12-11-2012 04:08 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57