Terry J. Reedy <tjre...@udel.edu> added the comment:

Ronald is correct, and for the reason given.  Python functions are lexically 
scoped, not dynamically scoped, and you are expecting the latter.  The exec 
global and local namespaces are used to resolve identifier in the code you 
pass.  Your first example passes 'func' and that is resolved to the 
*pre-compiled* function object which uses is lexicographical globals.  It does 
not contain the func-local 'var'.  You second example contains a def statement 
to be compiled in the exec namespaces.  Please post to python-list if you want 
further discussion.

----------
nosy: +terry.reedy
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue38331>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to