Status of PEP's?

James_Althoff at i2.com James_Althoff at i2.com
Thu Feb 28 20:06:54 EST 2002


[David Eppstein]
> I would argue with the "without success" opinion you express.
> I still like
>     for lower_bound <= var < upper_bound
> (or similar three-way comparisons, with middle argument of
> comparison required to be a variable), in parallelism with the current
> "for var in seq" with first argument of "in" required to be a variable.
> I guess we haven't made it into a PEP for the BDFL to rule on, if that's
> your measure of success, but the only arguments I can remember seeing
> against it are (1) some people view "in" as a keyword integrally attached
> to "for" rather than part of an expression, and don't like for loops
without
> "in", and (2) this isn't sufficiently terse for those situations where
you
> want an integer range outside of a for loop.  Am I misinterpreting the
> previous discussion?

I think this comment illustrates that a PEP would, in fact, be useful as a
way to focus discussion on this specific approach to dealing with integer
intervals.

For example, one problem I had when playing with an experimental
implementation of the "middle argument" variant mentioned above is that the
specific relational operators are tied to the values of the bounds.  If you
want to iterate from the smaller value (up) to the larger value you write:

for 1 <= var < 5:

whereas if you want to iterate from the larger value (down) to the smaller
value you have to turn things around and write:

for 5 > var >= 1:

which all looks very nice when you are dealing with literal constants.  But
suppose you have variables for the bounds, "start" and "end"?  Let's say I
have a function

def doSomethingFromTo(start,end):

The function has to test to see which of "start" and "end" is the smaller
value in order to know whether to execute a for-loop with "<" or a for-loop
with ">" (and the code specified in each separate for-loop has to be
written redundantly).  I found this to be awkward.

Another issue that I have is that the syntax does not work outside of a
for-loop header.  I want to be able to create integer intervals anywhere in
my code, not just in the header of a for-loop.

If a large-scale change (that includes new syntax) is to be made in Python
to handle general intervals, I would much rather see an approach that does
not have these drawbacks.

Other issues might surface if there were a proper PEP and discussion of
this specific suggestion.

Jim







More information about the Python-list mailing list