[Python-Dev] listcomps vs. for loops

Guido van Rossum guido at python.org
Tue Oct 21 12:56:31 EDT 2003


> > Anyway, this is no different from the
> > problem of:
> >
> > for x in R:
> > ...
> > print x
>> Well, yes. I still think it's dubious code.
>> > In any case, are there plans to also have the compiler emit
> > warnings about potential reliance on this feature?
>> I would hope that we wouldn't make changes without emitting such a
> warning. I'm not sure how hard it would be to implement, tho'.

Warning about what?
I have no intent to make the example quoted above illegal; a regular
for loop control variable's scope will extend beyond the loop.
It's only list comprehensions where I plan to remove x from the scope
after the comprehension is finished.
Do you need a warning for that change too? Code that relies on it is
pretty sick IMO.
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /