PEP 260: simplify xrange()

Guido van Rossum guido at python.org
Wed Jun 27 13:07:55 EDT 2001


James Logajan <JamesL at Lugoj.Com> writes:

> Guido van Rossum wrote:
> > Here's another sweet and short PEP.  What do folks think?  Is
> > xrange()'s complexity really worth having?
> 
> Are there still known bugs that will take some effort to repair? Is xrange
> constantly touched when changes are made elsewhere? If no to both, then I
> suggest don't fix what ain't broken; life is too short. (Unless it is
> annoying you to distraction, then do the deed and get it over with.)

I thought about adding an xrange-specific iterator to make it faster,
but found that the current implementation makes that more complicated
than it should be (because you have to keep track of repetitions).

It's also just an eyesore, and it seems to attract well-meaning folks
who want to make it more sequence-like (which has caused me and others
too much time already reviewing their code).

Others proposed to extend xrange() to grow a shortcut for
xrange(len(sequence)).  I'm not very keen on that; it's up to the
proposers to write the PEP that motivates it.  Note that there are
already other PEPs proposing to solve this problem differently, so
you'd have to explain why adding something to xrange() is a better.

I haven't heard any real objections here, so I'm going to go ahead and
make this change (ripping the fancy stuff from xrange()) later this
week.  Boy does that feel good. ;-)

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-list mailing list