ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

Mitya Sirenef msirenef at
Wed Dec 12 01:53:25 CET 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,

By the way, the Thesaurus class reminds me of using the old recipe
called 'Bunch':

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

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

Lark's Tongue Guide to Python:

More information about the Python-list mailing list