ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

Dave Cinege dave at
Wed Dec 12 23:20:53 CET 2012

On Wednesday 12 December 2012 15:42:36 Ian Kelly wrote:

> def __getattribute__(self, name):
>     if name.startswith('__') and name.endswith('__'):
>         return super(Thesaurus, self).__getattribute__(name)
>     return self.__getitem__(name)


Tested, and works as you advertised.

Isn't super() depreciated? I've replaced it with this:
-return super(Thesaurus, self).__getattribute__(name)
+return dict.__getattribute__(self, name)

Aside from a more palatable result in the python shell for otherwise bad 
code...does this get me anything else? Is it really worth the performance hit 
of 2 string comparisons for every getattribute call?

I also just reviewed all your original comments again:

In general: The recursion code is nothing special to me and I finally settled 
on the nested try's as something simple that 'just works good for now'. 

I think the concept of what I'm doing here is the big idea.

Should the idea of implementing what Thesaurus does in mainline python ever 
happen, those 10 lines of code will likely spark a 3 month jihad about how to 
properly do in python which up until now hasn't been something you do in 

To me for i in range(len(l)) seems like simpler, faster, tighter code for this 
now. It's duly noted that enumerate() is more python and I'm an old fart that 
still thinks too much in state machine. I've add except Exception per your 

What I'd really like to hear is that someone reading was curious enough to 
convert some existing code and their joy or displeasure with the experience.


More information about the Python-list mailing list