[Python-ideas] PEP 572 version 2: Statement-Local Name Bindings

Eric Fahlgren ericfahlgren at gmail.com
Sat Mar 24 12:34:57 EDT 2018


On Sat, Mar 24, 2018 at 7:14 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:

> ​​
>     >>> class C:
>     ...     sequence = range(10)
>     ...     listcomp = [x for x in sequence]
>

>>> class C:
...     y = 1
...     sequence = range(10)
...     listcomp = [x+y for x in sequence] ​
...
​Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 4, in C
  File "<stdin>", line 4, in <listcomp>
NameError: name 'y' is not defined
​

​Ok, so how does 'y' fit into these scoping rules?​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180324/a52c5c38/attachment-0001.html>


More information about the Python-ideas mailing list