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 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. ---------- messages: 248064 nosy: Peter Eastman priority: normal severity: normal status: open title: Incorrect handling of local variables in comprehensions with exec() type: behavior versions: Python 3.4 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue24800> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com