Re: Dynamic properties

2005-01-21 Thread Jeremy Bowers
On Fri, 21 Jan 2005 23:27:28 +0800, Craig Ringer wrote: > The chances are that whatever you want to do with dynamically created > properties is better done with __getattr__ and __setattr__ instead. Rather than post my own comment, I'd like to highlight this, emphasize it, and underline it twice. T

Re: Dynamic properties

2005-01-21 Thread Craig Ringer
On Fri, 2005-01-21 at 06:43 -0800, michael wrote: > setattr (self, key, property (fget, fset, fdel)) > it gives me > > > > What am I doing wrong here Properties must be defined in the class, not the instance, to work as expected. (Edit: Nick Coghlan explained this more accurately). You can

Re: Dynamic properties

2005-01-21 Thread Nick Coghlan
michael wrote: My first try is : fget = lambda self: mygetattr(self, attrname) fset = lambda self, value: mysetattr (self, attrname, value) fdel = lambda self: mydelattr(self, attrname) # fget, fset, fdel are used to reconstruct the byte field setattr (self, key, property (fget, fset, fdel)) setatt