Generator Comprehensions
Paul Rubin
phr-n2002a at nightsong.com
Tue Jan 29 18:22:09 EST 2002
"Tim Peters" <tim.one at home.com> writes:
> > Ah, well in that case, I can fall back on the excuse that "list
> > comprehensions are essentially syntactic sugar sprinkled on for
> > loops". ;-)
>
> That's not an excuse, it was the design. Python didn't even have nested
> scopes (in 2.2's sense) when listcomps were introduced, and it would have
> been horribly inconsistent if one and only one binding construct did not
> make its target name(s) local wrt to its scope. Had nested scopes been
> there at the time, it would have been more palatable to say that listcomps
> define a new scope -- but that would have been a surprise of a different
> kind (not to people coming from FP languages, but Python is not an FP
> language, and won't become one before Guido's death <wink>).
But Python 2.1 had nested scopes, as long as you imported them from
the future.
Having list comprehensions not define a new scope certainly seems like
a wart to me.
More information about the Python-list
mailing list