itertools comments [Was: Re: RELEASED: Python 2.3a2]

Chad Netzer cnetzer at mail.arc.nasa.gov
Thu Feb 20 18:28:45 EST 2003


On Thu, 2003-02-20 at 14:29, Raymond Hettinger wrote:

> For the time being, my goal is to start with a small set of
> tools that have proven useful in Haskell and SML.  Over
> time, other candidates will considered.

Would you be open to having an irange() call, that could be used instead
of xrange(), and would be able to return long integers (perhaps only
when appropriate)?

I've been (very casually) working on updating range() and xrange() to
work with Python long ints.  With xrange() it is tricky because I want
it to return the xrange() proxy, for backwards compatibility and speed,
except when longs are required.  My best option up to this point has
just been to make an xlrange() generator and leave xrange() alone.  This
could be an irange() instead, and range() could then easily be extended
(and xrange() left as is or deprecated).

This may sound like a pointless exercise (meant for language
'consistency' and having little practical value), but I've encountered
several bugs where people assume it will work, when doing things like:

range( long(1/small_float_value), long(1/another_small_float_value) )


Ultimately, I'd be happy if both of these worked:

a = long(1/1e-17)  # 100000000000000000L
range(a, a+10)
irange(a, a+10)

My current solution would be slightly uglier (IMO):

range(a, a+10)
xlrange(a, a+10)

If you'd accept an irange() patch, I'll send you one by next week...
(and if you accept it, I'll send a range() patch to sourceforge)

-- 
Bay Area Python Interest Group - http://www.baypiggies.net/

Chad Netzer
(any opinion expressed is my own and not NASA's or my employer's)







More information about the Python-list mailing list