Python recursively __getattribute__

Roman Dolgiy tosters at gmail.com
Mon Nov 22 11:41:49 EST 2010


On Nov 22, 6:04 pm, Andreas Waldenburger <use... at geekmail.INVALID>
wrote:
> On Mon, 22 Nov 2010 07:46:47 -0800 (PST) Roman Dolgiy <tost... at gmail.com> wrote:
>
> > Hello,
>
> > I need to implement such behavior:
>
> > obj.attr1.attr2.attr3 --> obj.attr1__attr2__attr3
> > 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...
>
> Why? No, really: Why?
>
> In that link you say that you need to do this to support legacy code. I still don't see how this would be necessary. If you need to support legacy code, doesn't that mean that the solution you're asking for already exists?
>
> I really think you should go into detail about why you need this. I'm certain that there's a better solution to your problem. ("Better" being one that is reasonably easy to implement and maintain.)
>
> /W
>
> --
> To reach me via email, replace INVALID with the country code of my home
> country.  But if you spam me, I'll be one sour Kraut.

I have a django project.

obj is django-haystack's SearchResult instance, it contains a lot of
de-normalized data (user__name, user__address) from django model, and
I need to access it as result.user.name for compability reasons.



More information about the Python-list mailing list