Status of PEP's?

James_Althoff at i2.com James_Althoff at i2.com
Mon Mar 4 18:52:45 EST 2002


[James_Althoff]
>
> > "for something" loops over all values of the variable that make
> > "something"  true.
>
> But that kind of definition isn't comprehensive enough because, for
> example, it says nothing about the order of the variables as processed by
> the for-loop.

[Greg Ewing]
> Obviously it doesn't serve as a complete *definition* of
> the semantics, but the complete definition is at least
> consistent with that view, for both "for i in x" and
> "for x < i < y".

Yes, I'll grant "is at least consistent".  But, in the case of the
for-loop, at some point -- rather quickly I suspect -- you are going to
have to leave the realm of relational operators and get right back to
talking about iterators.  Because you're going to have to explain why
    for x <= i <= y:
works and why
    for x <= i and i != y:
is a syntax error.

And why
    for i < rowcount:
uses "i" as the loop variable instead of "rowcount" -- or does it?
    for rowcount < i:
How would Python decide?

And if it can't, then does this mean that the idiom cannot support
shortcuts for the common case of iterating the indices of a list?  So, do
we have to write:
    for 0 <= i < rowcount:
specifying the "0 <=" part every time?

Jim





More information about the Python-list mailing list