On Fri, Aug 10, 2012 at 4:44 PM, Jaidev Deshpande
<[email protected]> wrote:
> Hi,
>
> Supposed I have a string containing a python script and I exec that script.
>
> Is there a way to keep track of the variables that this exec() command
> creates?
Sure. You can provide the dictionaries that exec will use for globals
and locals. So, something like this might get you started:
>>> my_globals = {}
>>> my_locals = {}
>>> exec "favorite_color = 'blue'" in my_globals,my_locals
>>> print(my_locals)
{'favorite_color': 'blue'}
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor