[Python-Dev] listcomps vs. for loops

Michael Chermside mcherm at mcherm.com
Mon Oct 20 14:06:52 EDT 2003

> We are indeed sure (sadly) that list comprehensions leak control
> variable names.

> But they shouldn't.  It can be fixed by renaming them (e.g. numeric
> names with a leading dot).

> ?!?!  When listcomps were introduced, you were strongly against [...]
> Are you changing your position[...]?

> 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. 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.

-- Michael Chermside

More information about the Python-Dev mailing list