xrange question

Tim Peters tim.one at home.com
Sun May 6 20:35:12 CEST 2001


[John Flynn]
> I'm puzzled about the purpose of xrange.

Carlos Ribeiro gave some excellent answers, so I'll skip to this one:

> ...
> Secondly, it seems that the size of a sequence generated by xrange is
> limited to INT_MAX. Is there a good reason for this?

Just because it's a minor variant of range(), which is also limited to
sys.maxint (which may be much bigger than INT_MAX, depending on the
platform).  If you're on a 32-bit platform, try range(2000000000) and see
what happens <wink>.

Given the way the interpreter is currently written, it's simply easier and
faster to stick with native C longs when possible.  This is becoming harder
to live with over time, though, as 2**31 is no longer "essentially infinity"
for all practical problems.  So Python is slowly eradicating the user-visible
differences between its bounded and unbounded integral types, and someday I
expect neither range() nor xrange() will care about native C integer sizes.

and-someday-after-that-people-will-implement-c-in-python-ly y'rs  - tim





More information about the Python-list mailing list