Message353995
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:40 | terry.reedy | set | recipients:
+ terry.reedy, ronaldoussoren, Krishna Oza, Huyston |
2019-10-05 06:23:39 | terry.reedy | set | messageid: <1570256619.96.0.83896826246.issue38331@roundup.psfhosted.org> |
2019-10-05 06:23:39 | terry.reedy | link | issue38331 messages |
2019-10-05 06:23:39 | terry.reedy | create | |
|