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

Paddy paddy3118 at googlemail.com
Thu Aug 11 22:31:45 CEST 2011


On Aug 11, 8:48 am, Terry Reedy <tjre... at udel.edu> wrote:
> On 8/11/2011 3:19 AM, Paddy wrote:
>
> > 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.
>
> Right. That was and is Python's execution model.
> Note that when you exec code, including a function call, the locals
> passed is the local context in which the code is executed. It is not the
> locals of any particular function called by the exec-ed code.
>
> If you exec a function that is a closure, the closure or non-local
> objects come with the function. A 'stack of dicts' has nothing to do
> with how function and nested funcs operate.
>
> --
> Terry Jan Reedy

Thanks Terry.



More information about the Python-list mailing list