[Tutor] xrange() with start or stop > sys.maxint?

Terry Carroll carroll at tjc.com
Thu May 19 03:17:44 CEST 2011


Is there any way to use xrange with a start or stop value that exceeds 
sys.maxint?

>>> import sys
>>> print sys.maxint
2147483647
>>> start = sys.maxint-1
>>> for i in xrange(start, start+1):
...   pass
...
>>> start = sys.maxint
>>> for i in xrange(start, start+1):
...   pass
...
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
OverflowError: Python int too large to convert to C long
>>>

Works okay with range, though:

>>> start = sys.maxint
>>> for i in range(start, start+1):
...   pass
...
>>>


More information about the Tutor mailing list