(x)range( 40000000000, 40000000001 )

Raymond Hettinger vze4rx4y at verizon.net
Sun Jun 29 15:56:24 EDT 2003


> It seems range and xrange don't like longs that can't be sqeezed into ints:
>
> With Python 2.3b1+:
>
>  >>> xrange( 40000000000, 40000000001 )
> Traceback (most recent call last):
>    File "<stdin>", line 1, in ?
> OverflowError: long int too large to convert to int
>  >>> range( 40000000000, 40000000001 )
> Traceback (most recent call last):
>    File "<stdin>", line 1, in ?
> OverflowError: long int too large to convert to int
>  >>>
>
> Its not a critical problem, and I can find a way around it.  It's a just
> little disconcerting that (x)range doesn't work with big longs, and it
> seems it would not be too difficult to make work.

This is intentional.
xrange() is meant to be a fast, lightweight alternative to range().
It has been given the minimum possible functionality.
Use range() or a generator to meet other needs.


Raymond Hettinger






More information about the Python-list mailing list