Python recursively __getattribute__

Roman Dolgiy tosters at gmail.com
Mon Nov 22 15:44:15 EST 2010


On Nov 22, 7:57 pm, Terry Reedy <tjre... at udel.edu> wrote:
> 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.
> >http://stackoverflow.com/questions/4247036/python-recursively-getattr...
>
> The code posted there by THC4k depened on such knowledge, which you gave
> there but not here.
>
> --
> Terry Jan Reedy

I need to support a lot of legacy code, with THC4k's approach I'll
have to modify project's existing code to use obj.attr1.val instead of
obj.attr1 but this is not suitable.



More information about the Python-list mailing list