Python 3.X: nonlocal support in eval/exec?

Paddy paddy3118 at googlemail.com
Thu Aug 11 03:19:34 EDT 2011


We can access nonlocal variables in a function, but if we were to eval/
exec the function we cannot set up a nested stack of evironment dicts.
We are limited to just two: global and local.

How about eval/exec take a new env argument that is a nested
dictionary whose outer level corresponds to locals, and which has a
__up__ value which is the next outer level environment dict. The
outermost level of the nested dictionary would correspond to the
global level?

I haven't given much thought to my suggested solution - I just didn't
want to leave a possible solution out. The major point is that there
seems to be no support for nonlocal in eval/exec (unless, trivially,
nonlocal==global).

- Paddy.



More information about the Python-list mailing list