Incorrect scope of list comprehension variables
Aahz
aahz at pythoncraft.com
Fri Apr 16 11:48:03 EDT 2010
In article <4bb92850$0$8827$c3e8da3 at news.astraweb.com>,
Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au> wrote:
>
>Nevertheless, it is a common intuition that the list comp variable should
>*not* be exposed outside of the list comp, and that the for-loop variable
>should. Perhaps it makes no sense, but it is very common -- I've never
>heard of anyone being surprised that the for-loop variable is exposed,
>but I've seen many people surprised by the fact that list-comps do expose
>their loop variable.
I've definitely seen people surprised by the for-loop behavior.
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
"It is easier to optimize correct code than to correct optimized code."
--Bill Harlan
More information about the Python-list
mailing list