On Sun, Nov 29, 2009 at 7:53 PM, Tim Chase
<python.l...@tim.thechases.com> 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)

locals()["hello"]  and  globals()["hello"], respectively

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to