Message 337980 - Python tracker (original) (raw)

The following code fails:

>>> lcls = {'w': 100}
>>> eval('[w for x in ("hello", "world")]', None, lcls)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 1, in <module>
  File "<string>", line 1, in <listcomp>
NameError: name 'w' is not defined
>>> eval('[w, w, w]', None, lcls)
[100, 100, 100]

whereas in python2 it succeeds

>>> lcls = {'w': 100}
>>> eval('[w for x in ("hello", "world")]', None, lcls)
[100, 100]