Re: How to use dynamic properties? <-- Noob

2007-01-24 Thread Sean Schertell
Yep, that was it. Thanks Gary :-) Sean On Jan 23, 2007, at 5:05 PM, Gary Herron wrote: > Sean Schertell wrote: >> person.name = 'Joe' >> person.age = 20 >> person.sex = 'm' >> >> info_I_need = name >> >> print person.info_I_need >> >> # How can I make it print 'Joe' ? >> >> >> Sean >> >> >> ::

Re: How to use dynamic properties? <-- Noob

2007-01-23 Thread Bruno Desthuilliers
Sean Schertell a écrit : > person.name = 'Joe' > person.age = 20 > person.sex = 'm' > > info_I_need = name > > print person.info_I_need > > # How can I make it print 'Joe' ? > print getattr(person, "name") -- http://mail.python.org/mailman/listinfo/python-list

Re: How to use dynamic properties? <-- Noob

2007-01-23 Thread Gary Herron
Sean Schertell wrote: > person.name = 'Joe' > person.age = 20 > person.sex = 'm' > > info_I_need = name > > print person.info_I_need > > # How can I make it print 'Joe' ? > > > Sean > > > DataFly.Net > Complete Web Services > http://www.datafly.net > > Like this: info_I_need = '

How to use dynamic properties? <-- Noob

2007-01-23 Thread Sean Schertell
person.name = 'Joe' person.age = 20 person.sex = 'm' info_I_need = name print person.info_I_need # How can I make it print 'Joe' ? Sean DataFly.Net Complete Web Services http://www.datafly.net -- http://mail.python.org/mailman/listinfo/python-list

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

Dynamic properties

2005-01-21 Thread michael
Hello again, I have a dictionary with the following content : 'LZ': {'type': 'N', 'bytes': '8'}, 'LVI000': {'type': 'N', 'bytes': '10'} This could be seen as a interface description to deal with an external program that needs a 18 Byte communication area. 8 and 18 Bytes have to be interp