Status of PEP's?

James_Althoff at i2.com James_Althoff at i2.com
Mon Mar 4 16:29:06 EST 2002


[Jeff Hinrichs]
> How can one iterate over something that is not a
> sequence/collection?

By defining the method __iter__(self) to return an iterator object <wink>.
Iterators are very useful and general-purpose.  No need to confine them
just to sequences.


> I haven't seen any argument on why range/xrange is less preferrable to
iterable integers.

The advantage that iter(n) has over range(n) and xrange(n) is that Python
calls iter automatically.


> I've heard the philosophical debate but not seen how python
> would be better for this addition.  If a good, tangible case
> were made I could be influenced.
> It would have to be a stronger case than:
> for i in 5:  is better than   for i in range(5):
>     print i                       print i

Please refer to the PEP.  There is a "rationale" section.  "for i in 5"
happens to work and I would wager would become popular when typing into the
intepreter, for example.  But, it is not the motivating example in the PEP.


> **Not everything is an object.**

Fortunately, in Python it is <wink>.


> Numbers don't perform operations

... and they can <wink>

>>> -3 .__abs__()
-3
>>>


> It is not natural to consider a number as a collection of other
> numbers.

So don't consider that.  Just consider whether or not it would be useful to
get an iterator from a number <wink>.

Jim




More information about the Python-list mailing list