Author r.david.murray
Recipients docs@python, krichter, r.david.murray
Date 2014-06-12.19:51:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1402602711.96.0.407581429057.issue21739@psf.upfronthosting.co.za>
In-reply-to
Content
In 3.x a list comprehension (like a generator expression in 2.x) *is* a separate block:

>>> [x for x in range(3)]
[0, 1, 2]
>>> x
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'x' is not defined

I note that this is not in fact mentioned in the python3 version of the tutorial; there it still implies that it is completely equivalent to the unrolled if statement, which would imply it *was* in the same scope.

IMO the 2.7 tutorial is complete in the sense that the "is equivalent to" example is clearly in the same scope, while the python3 tutorial is missing a note that the comprehension is its own scope.  Given the fact that it is *different* between the two, I wonder if it would be appropriate to add a note (footnote?) to that effect to the 2.7 tutorial.  There is such a footnote in the corresponding part of the language reference.
History
Date User Action Args
2014-06-12 19:51:52r.david.murraysetrecipients: + r.david.murray, docs@python, krichter
2014-06-12 19:51:51r.david.murraysetmessageid: <1402602711.96.0.407581429057.issue21739@psf.upfronthosting.co.za>
2014-06-12 19:51:51r.david.murraylinkissue21739 messages
2014-06-12 19:51:51r.david.murraycreate