Re: Python recursively __getattribute__

2010-11-23 Thread Roman Dolgiy
Thanks to Andreas Waldenburger, THC4k (http://stackoverflow.com/ questions/4247036/python-recursively-getattribute) and others for their tips. I was able to find solution: class Null(object): def __repr__(self): return "" def __str__(self): return '' def __nonzero__(s

Re: Python recursively __getattribute__

2010-11-23 Thread bruno.desthuilli...@gmail.com
On 22 nov, 21:44, Roman Dolgiy wrote: >> http://stackoverflow.com/questions/4247036/python-recursively-getattr... > > 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. Y

Re: Python recursively __getattribute__

2010-11-22 Thread Roman Dolgiy
On Nov 22, 7:57 pm, Terry Reedy 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

Re: Python recursively __getattribute__

2010-11-22 Thread Terry Reedy
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.

Re: Python recursively __getattribute__

2010-11-22 Thread Andreas Waldenburger
On Mon, 22 Nov 2010 08:41:49 -0800 (PST) Roman Dolgiy wrote: > On Nov 22, 6:04 pm, Andreas Waldenburger > wrote: > > On Mon, 22 Nov 2010 07:46:47 -0800 (PST) Roman Dolgiy > > wrote: > > > > > Hello, > > > > > I need to implement such behavior: > > > > > obj.attr1.attr2.attr3 --> obj.attr1__attr

Re: Python recursively __getattribute__

2010-11-22 Thread Roman Dolgiy
On Nov 22, 6:04 pm, Andreas Waldenburger wrote: > On Mon, 22 Nov 2010 07:46:47 -0800 (PST) Roman Dolgiy > 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 als

Re: Python recursively __getattribute__

2010-11-22 Thread Andreas Waldenburger
On Mon, 22 Nov 2010 07:46:47 -0800 (PST) Roman Dolgiy 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 muc