Re: setattr getattr confusion

2007-12-08 Thread Donn Ingle
Thanks Bruno, I had to keep coding, so I used the long form [Object.subobject.property = blah] anyway. It's long-winded, but unambiguous. \d -- http://mail.python.org/mailman/listinfo/python-list

Re: setattr getattr confusion

2007-12-08 Thread Bruno Desthuilliers
Donn Ingle a écrit : >>class Key(object): >>def __init__self): >>self.__dict__['props'] = KeyProps() > > Okay - that's weird. No, that's coherent. The default behavior (I mean, when there's no descriptor involved etc) of __setattr__ is to store attributes in instance.__dict__. So as long a you

Re: setattr getattr confusion

2007-12-08 Thread Donn Ingle
> class Key(object): > def __init__self): > self.__dict__['props'] = KeyProps() Okay - that's weird. Is there another way to spin this? > def __setattr__(self,var,val): > setattr(self.props,var,val) Perhaps by changing this one? \d -- http://mail.python.org/mailman/listinfo/python-list

Re: setattr getattr confusion

2007-12-08 Thread Steven D'Aprano
On Sat, 08 Dec 2007 14:26:00 +0200, Donn Ingle wrote: >> So you might want to describe your use-case. > Um.. I wanted an object with Key to hold other data. I wanted a way to > set that *other* data within Key without having to specify the "object > in-between" everytime. That's called "automatic

Re: setattr getattr confusion

2007-12-08 Thread Carl Banks
On Dec 8, 6:06 am, Donn Ingle <[EMAIL PROTECTED]> wrote: > Hi, > Here's some code, it's broken: > > class Key( object ): > def __init__(self): > self.props = KeyProps() > def __getattr__(self, v): > return getattr( self.props,v ) > def __setattr__(self,var,val): >

Re: setattr getattr confusion

2007-12-08 Thread Donn Ingle
> So you might want to describe your use-case. Um.. I wanted an object with Key to hold other data. I wanted a way to set that *other* data within Key without having to specify the "object in-between" everytime. k1.x = "ni!" should perform: k1.props.x = "ni!" and print k1.x should perform: print

Re: setattr getattr confusion

2007-12-08 Thread James Stroud
Donn Ingle wrote: > Hi, > Here's some code, it's broken: > > > class Key( object ): > def __init__(self): > self.props = KeyProps() > def __getattr__(self, v): > return getattr( self.props,v ) > def __setattr__(self,var,val): > object.__setattr__(self.props,va

setattr getattr confusion

2007-12-08 Thread Donn Ingle
Hi, Here's some code, it's broken: class Key( object ): def __init__(self): self.props = KeyProps() def __getattr__(self, v): return getattr( self.props,v ) def __setattr__(self,var,val): object.__setattr__(self.props,var,val) class KeyProps(object):