Long overflow problem

Erik Max Francis max at alcyone.com
Wed Nov 6 19:29:56 EST 2002


Tom wrote:

> def myFunc (i, j):
>    for a in range(i, j):
>       print a
> 
> I get the same error. Are there any implicit conversions going on
> here?

Yes, range only accepts two ints.  This really shouldn't be too
surprising; range actually builds a list, so if you really need to talk
about numbers that different enough that you need longs, you pro-obably
don't want to build a list containing all those values.

If the size of the range (j - i) is small, then you could simply call
range with the difference (an int) and each time through the loop add it
to i (a long).  Otherwise, just start with i, and keep adding 1 until
you get to j.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ Awards are merely the badges of mediocrity.
\__/ Charles Ives
    EmPy / http://www.alcyone.com/pyos/empy/
 A system for embedding arbitrary Python in template text as markup.



More information about the Python-list mailing list