[Python-Dev] listcomps vs. for loops
Guido van Rossum
guido at python.org
Mon Oct 20 14:23:15 EDT 2003
> Alex:
> > We are indeed sure (sadly) that list comprehensions leak control
> > variable names.
>
> Guido:
> > But they shouldn't. It can be fixed by renaming them (e.g. numeric
> > names with a leading dot).
>
> Aahz:
> > ?!?! When listcomps were introduced, you were strongly against [...]
> > Are you changing your position[...]?
>
> Guido:
> > Did I say it was a feature that
> >
> > L = [x for x in R]
> > print x
> >
> > would print the last item of R?
>
> Well, I don't care much about the history of what you may have said...
> let's get it out in the open: The fact that listcomps leak their
> variable (thus providing a handy name-binding expression for the evil-minded
> among us) is a BAD THING.
>
> I'd love to see that (mis)feature removed someday. I'd love to have that
> made possible by Guido's _immediately_ and _officially_ declaring it to be
> an unsupported (and deprecated) feature.
Make it so.
> Then maybe *someday* we could
> get rid of them. Even now, people are writing code that (ab)uses this,
> and making it ever harder to ever change this in the future.
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev
mailing list