Variable by label
Arnaud Delobelle
arnodel at googlemail.com
Fri May 16 10:09:29 EDT 2008
rocco.ro... 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.
There are the globals() and locals() builtins.
>>> a = 42
>>> globals()['a']
42
>>>
--
Arnaud
More information about the Python-list
mailing list