Variable by label
Duncan Booth
duncan.booth at invalid.invalid
Fri May 16 10:14:47 EDT 2008
rocco.rossi at gmail.com wrote:
> Is there any function which will return a variable by passing to it
> the string containing the variable's name? Something like this for
> instance:
>
> foo = some_function("foo")
>
> or perhaps it's a dictionary. I don't know, but I would really like to
> find out how it can be done. I guess it is achievable.
>
> Thank you.
>
vars()["foo"]
but if you are doing this you are almost certainly making your life harder
than it needs to be. Usually you really just want to keep the values in a
dict.
--
Duncan Booth http://kupuguy.blogspot.com
More information about the Python-list
mailing list