[Python-Dev] Propose to reject PEP 276 -- Simple iterator for ints

Raymond Hettinger raymond.hettinger at verizon.net
Fri Jun 17 07:19:51 CEST 2005


The principal use case was largely met by enumerate().  From PEP 276's
rationale section:

"""
A common programming idiom is to take a collection of objects and apply
some operation to each item in the collection in some established
sequential order.  Python provides the "for in" looping control
structure for handling this common idiom.  Cases arise, however, where
it is necessary (or more convenient) to access each item in an "indexed"
collection by iterating through each index and accessing each item in
the collection using the corresponding index.
"""

Also, while some nice examples are provided, the proposed syntax allows
and encourages some horrid examples as well:

    >>> for i in 3: print i
    0
    1
    2

The backwards compatability section lists another problematic
consequence; the following would stop being a syntax error and would
become valid:

   x, = 1

The proposal adds iterability to all integers but silently does nothing
for negative values.

A minor additional concern is that floats are not given an equivalent
capability (for obvious reasons) but this breaks symmetry with
range/xrange which still accept float args.


Raymond



More information about the Python-Dev mailing list