PEP 284, Integer for-loops
tdelaney at avaya.com
Thu Mar 7 01:44:52 CET 2002
> From: David Eppstein [mailto:eppstein at ics.uci.edu]
> When you say "incorrect", do you mean that "making integers
> iterable" is
> different from "allowing automatic conversion of integers to
> It was my understanding that "for x in y" and "if x in y"
> converted y to
> an iterator automatically, by calling iter(y) if necessary. Integers
> can be made iterable now, by calling range() on them, but that is not
That's automatic, but not a *conversion*. It is asking the iterable object
to *supply* an iterator. Calling range() on an integer does not make the
integer iterable ... it creates an (iterable) list using the integer as one
of the bounds.
> In what way would you propose rewording the PEP? If it's
> just "PEP 274
>  proposes to make integers iterable, simplifying..." that seems
> unobjectionable enough.
Or possibly make it more explicit ...
"PEP 274  proposes to make integers iterable by implementing __iter__,
I would also possibly add the discussion of what iter(-x) should mean i.e.
either counting up from -x to 0 (upper bound exclusive, matches slice
semantics), or counting down from 0 to -x (upper bound exclusive, useful for
traversing sequences in reverse order).
More information about the Python-list