Message248075
I don't believe that explanation is correct. You can just as easily get the same problem without explicitly passing a map to exec(). For example:
def f():
script = """
print(a)
print([a for i in range(5)])
"""
a = 5
exec(script)
f()
The documentation for exec() states, "In all cases, if the optional parts are omitted, the code is executed in the current scope." Therefore the code above should be exactly equivalent to the following:
def f():
a = 5
print(a)
print([a for i in range(5)])
f()
But the latter works and the former doesn't. Contrary to the documentation, the code is clearly not being executed in the same scope. |
|
Date |
User |
Action |
Args |
2015-08-05 20:33:59 | Peter Eastman | set | recipients:
+ Peter Eastman, r.david.murray |
2015-08-05 20:33:59 | Peter Eastman | set | messageid: <1438806839.14.0.828241700546.issue24800@psf.upfronthosting.co.za> |
2015-08-05 20:33:59 | Peter Eastman | link | issue24800 messages |
2015-08-05 20:33:58 | Peter Eastman | create | |
|