This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Peter Eastman
Recipients Peter Eastman
Date 2015-08-05.19:44:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1438803881.09.0.804532346481.issue24800@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2015-08-05 19:44:41Peter Eastmansetrecipients: + Peter Eastman
2015-08-05 19:44:41Peter Eastmansetmessageid: <1438803881.09.0.804532346481.issue24800@psf.upfronthosting.co.za>
2015-08-05 19:44:40Peter Eastmanlinkissue24800 messages
2015-08-05 19:44:40Peter Eastmancreate