On 6/8/2018 6:07 PM, Michael Selik wrote:
You can use ``eval`` to run an expression, swapping in a different globals and/or locals namespace. Will this serve your purpose?

In [1]: import types
In [2]: ns = types.SimpleNamespace(a=1)
In [3]: eval('a', ns.__dict__)
Out[3]: 1

https://docs.python.org/3/library/functions.html#eval

Or exec to run statements in namespaces. This is how IDLE, and I am sure, at least some other IDEs, execute user code in a simulated __main__ namespace.

--
Terry Jan Reedy

_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to