Variable by label

inhahe inhahe at gmail.com
Fri May 16 10:27:45 EDT 2008


>>> a = 1
>>> b = eval("a")
>>> b
1
>>> a =1
>>> b = globals()["a"]
>>> b
1
>>> a =1
>>> b = locals()["a"]
>>> b
1
<rocco.rossi at gmail.com> wrote in message 
news:aec6cdd8-3bde-4d68-ad93-d9ece9567886 at b1g2000hsg.googlegroups.com...
> 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. 





More information about the Python-list mailing list