variable variables
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Fri Jun 18 06:01:01 EDT 2010
En Fri, 18 Jun 2010 06:48:34 -0300, someone <petshmidt at googlemail.com>
escribió:
> is it possible to make first attr variable?
>
> some_object.attr.attr
>
> so instead of attr I could use self.foo which has value "attr"
I think you're looking for getattr:
http://docs.python.org/library/functions.html#getattr
name = "spam"
getattr(some_object, name) == some_object.spam == getattr(some_object,
"spam")
--
Gabriel Genellina
More information about the Python-list
mailing list