[Python-ideas] A "within" keyword

Terry Reedy tjreedy at udel.edu
Fri Jun 8 23:13:19 EDT 2018

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

More information about the Python-ideas mailing list