New submission from Peter Eastman:
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 fol
Peter Eastman added the comment:
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
Peter Eastman added the comment:
Then fix the documentation. This behavior directly contradicts the
documentation of the exec() function. The question is not what scope the
comprehension runs in, it's what scope the script runs in. See my third
example. A comprehension in the f() fun