This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients Huyston, Krishna Oza, ronaldoussoren, terry.reedy
Date 2019-10-05.06:23:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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.
Date User Action Args
2019-10-05 06:23:40terry.reedysetrecipients: + terry.reedy, ronaldoussoren, Krishna Oza, Huyston
2019-10-05 06:23:39terry.reedysetmessageid: <>
2019-10-05 06:23:39terry.reedylinkissue38331 messages
2019-10-05 06:23:39terry.reedycreate