Chris Billington <chrisjbilling...@gmail.com> added the comment:

Sorry for the spamming, realised I misunderstood further.

The original behaviour isn't because the exec'd code can't create new local 
variables - it can - it's because of the documented behaviour of exec when it 
gets different dicts for globals and locals:

"If exec gets two separate objects as globals and locals, the code will be 
executed as if it were embedded in a class definition"

So the new scope made by the list comprehension can't access the enclosing 
scope in which the new variable was defined, because that's how scoping works 
in class definitions.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue38937>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to