How to use dynamic properties? <-- Noob
Sean Schertell
sean at datafly.net
Wed Jan 24 03:06:17 EST 2007
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
>>
>>
>> :::: DataFly.Net ::::
>> Complete Web Services
>> http://www.datafly.net
>>
>>
> Like this:
>
> info_I_need = 'name'
>
> print getattr(person, info_I_need)
>
> Related to getattr are setattr and hasattr.
> Gary Herron
>
>
>
>
:::: DataFly.Net ::::
Complete Web Services
http://www.datafly.net
More information about the Python-list
mailing list