xrange() question

Bob Gailer bgailer at alum.rpi.edu
Tue Aug 5 10:57:35 EDT 2003


At 02:27 PM 8/5/2003 +0000, George Trojan wrote:

>Why do I get an overflow error here:
>
> > /usr/bin/python
>Python 2.2.2 (#1, Feb 24 2003, 19:13:11)
>[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-4)] on linux2
>Type "help", "copyright", "credits" or "license" for more information.
> >>> import sys
> >>> for n, x in zip(range(4), xrange(0, sys.maxint, 2)):
>...     print n, x
>...
>Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
>OverflowError: integer addition
>
>but not here:
>
> >>> for n, x in zip(range(8), xrange(0, sys.maxint)):
>...     print n, x
[snip]
Consider:

 >>> for x in xrange(sys.maxint-2,sys.maxint,2):x
...
2147483645

for x in xrange(sys.maxint-1,sys.maxint,2):x
...
Traceback (most recent call last):
   File "<interactive input>", line 1, in ?
OverflowError: integer addition

Does this give you any clues?

Bob Gailer
bgailer at alum.rpi.edu
303 442 2625
-------------- next part --------------

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003


More information about the Python-list mailing list