Message388366
exec() ignores scope.
Code:
--------------------------
class ExecTest:
def public(self):
h=None
exec("h='It is public'")
print(h)
self._private()
def _private(self):
h=None
exec("h='It is private'", globals(), locals())
print(h)
h = None
exec("h='It is global'")
print(h)
e=ExecTest()
e.public()
Result
--------------------------
It is global
None
None
--------------------------
Python 3.7.10 (default, Feb 26 2021, 13:06:18) [MSC v.1916 64 bit (AMD64)]
and
Python 3.8.5 (default, Jan 27 2021, 15:41:15) [GCC 9.3.0] |
|
Date |
User |
Action |
Args |
2021-03-09 15:42:58 | Keepun | set | recipients:
+ Keepun |
2021-03-09 15:42:58 | Keepun | set | messageid: <1615304578.57.0.704046890189.issue43448@roundup.psfhosted.org> |
2021-03-09 15:42:58 | Keepun | link | issue43448 messages |
2021-03-09 15:42:58 | Keepun | create | |
|