Python recursively __getattribute__

Terry Reedy tjreedy at
Mon Nov 22 18:57:18 CET 2010

On 11/22/2010 10:46 AM, Roman Dolgiy wrote:
> Hello,
> I need to implement such behavior:
> obj.attr1.attr2.attr3 -->  obj.attr1__attr2__attr3

obj.attr1.attr2.attr3 is parsed as ((obj.attr1).attr2).attr3,
so this cannot work in general but only if attr1 and attr2 are known to 
not be 'final' names.

> It looks like I have to override obj's class __getattribute__ and also
> use python descriptors somehow.
> Any help will be much appreciated.

The code posted there by THC4k depened on such knowledge, which you gave 
there but not here.

Terry Jan Reedy

More information about the Python-list mailing list