While xrange does have it's place in Python, it has very few actual uses
(yours being one of the few), and is usually more harmful than beneficial.
While the deprecation of xrange is not that "soon", it is part of the
Python 3000 PEP (
http://www.python.org/peps/pep-3000.html#id38) along
with the deprecation of most FP-facilities of Python (filter, map, reduce).
Er, I thought it was range that was being depreciated, and xrange being
renamed range?
Or if you prefer, xrange being depreciated, and range being turned into an
iterator just like xrange *wink*
(I'm aware that xrange isn't implemented as an iterator, or at least it
wasn't, it was a unique object type. But it is conceptually an iterator.)
It should also be noted that reimplementing xrange when needed is
trivial and can be done with a 5-lines generator for the minimal version
(1 argument, 0-n range) and probably less than 10 lines for the full
blown version equivalent to the current one (including start, end and
step arguments)
I have a problem with this attitude. Yes, it is true that many of the
features of Python scheduled for eventual depreciation in Python 3.0 (map,
filter, str.find, xrange, etc.) can easily be re-written in just a couple
of lines.
But these functions are useful, and I don't see that it is a step forward
to remove useful functionality from the language and expect people to fill
their programs with boilerplate code recreating that lost functionality.
Guido introduced True, False because so many people were writing
False = 0; True = not False
at the start of their code. Will Guido end up re-introducing str.find
to Python 4.0 because people define this in all their code (complete with
deliberately included bug)?
def find(s, target, start=None, end=None):
try:
return s.index(target, start, end)
except:
return -1
On the other hand, there are genuine improvements: apply(f, L) is *much*
better written as f(*L). I don't think anyone will miss apply.