[ python-Bugs-1110705 ] list comprehension scope
SourceForge.net
noreply at sourceforge.net
Thu Jan 27 15:11:06 CET 2005
Bugs item #1110705, was opened at 2005-01-27 15:27
Message generated for change (Comment added) made by sdahlbac
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1110705&group_id=5470
Category: Python Interpreter Core
Group: Python 2.4
Status: Closed
Resolution: Invalid
Priority: 5
Submitted By: Simon Dahlbacka (sdahlbac)
Assigned to: Nobody/Anonymous (nobody)
Summary: list comprehension scope
Initial Comment:
The variable used for iteration in list comprehensions
is still in scope after the list comprehension.
>>>foo = [1, 2, 3]
>>>bar = [dummy + 1 for dummy in foo]
>>>dummy
3
Expected result: NameError: name 'dummy' is not defined
----------------------------------------------------------------------
>Comment By: Simon Dahlbacka (sdahlbac)
Date: 2005-01-27 16:11
Message:
Logged In: YES
user_id=750513
Seemingly (according to:
http://docs.python.org/ref/lists.html) this is indeed a bug
that should be fixed.
----------------------------------------------------------------------
Comment By: Raymond Hettinger (rhettinger)
Date: 2005-01-27 15:48
Message:
Logged In: YES
user_id=80475
This is not a bug. It is behaving as designed. The thought
was to emulate the behavior of an equivalent for-loop.
In future versions of Python, Guido would like to change the
design to hide the induction variable. So, someday, you'll
get your wish.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1110705&group_id=5470
More information about the Python-bugs-list
mailing list