How to use dynamic properties? <-- Noob

Gary Herron gherron at islandtraining.com
Tue Jan 23 03:05:33 EST 2007


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







More information about the Python-list mailing list