dynamic variables; globals
Randy Heiland
heiland at ncsa.uiuc.edu
Wed Jan 22 07:12:05 EST 2003
I want to do something like the following:
>>> def func(sarg):
... exec(sarg)
...
>>> func('foo=11')
>>> func('print foo')
but of course, I get the following:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 2, in func
File "<string>", line 1, in ?
NameError: name 'foo' is not defined
Style & security notwithstanding, is there some way to add a dynamic
variable to the globals list?
thanks,
Randy
More information about the Python-list
mailing list