Message248064
The following script demonstrates a bug in the exec() function in Python 3.4. (It works correctly in 2.7).
script = """
print(a)
print([a for i in range(5)])
"""
exec(script, globals(), {"a":5})
It produces the following output:
5
Traceback (most recent call last):
File "test.py", line 5, in <module>
exec(script, globals(), {"a":5})
File "<string>", line 3, in <module>
File "<string>", line 3, in <listcomp>
NameError: name 'a' is not defined
The variable "a" is getting passed to the script, as expected: printing it out works correctly. But if you use it in a comprehension, the interpreter claims it does not exist. |
|
Date |
User |
Action |
Args |
2015-08-05 19:44:41 | Peter Eastman | set | recipients:
+ Peter Eastman |
2015-08-05 19:44:41 | Peter Eastman | set | messageid: <1438803881.09.0.804532346481.issue24800@psf.upfronthosting.co.za> |
2015-08-05 19:44:40 | Peter Eastman | link | issue24800 messages |
2015-08-05 19:44:40 | Peter Eastman | create | |
|