Noobie python shell question

Dave Angel davea at ieee.org
Sun Nov 29 23:30:09 EST 2009



Tim Chase wrote:
> <snip>
>
> (as an aside, is there a way to get a local/global variable from a 
> string like one can fetch a variable from a class/object with 
> getattr()?  Something like getattr(magic_namespace_here, "hello") used 
> in the above context?  I know it can be done with eval(), but that's 
> generally considered unsafe unless you vet your input thoroughly)
>
>
I think you're looking for
     globals()["hello"],    or of course magic_namespace=globals()

DaveA




More information about the Python-list mailing list