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 <1570256619.96.0.83896826246.issue38331@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2019-10-05 06:23:40terry.reedysetrecipients: + terry.reedy, ronaldoussoren, Krishna Oza, Huyston
2019-10-05 06:23:39terry.reedysetmessageid: <1570256619.96.0.83896826246.issue38331@roundup.psfhosted.org>
2019-10-05 06:23:39terry.reedylinkissue38331 messages
2019-10-05 06:23:39terry.reedycreate