Dick Moores wrote:
> >>> for x in xrange(2**31):
> pass
>
> Traceback (most recent call last):
> File "<pyshell#16>", line 1, in <module>
> for x in xrange(2**31):
> OverflowError: long int too large to convert to int
> >>>
>
> I can think of 2 workarounds for this 2**31 limitation in xrange().
> Use a while loop instead. Or use 2 or more for loops, keeping the
> number of cycles in each under 2**31.
>
> Are there others?
Encapsulate the while loop in a generator:
def count(limit):
n=0
while n<limit:
yield n
n += 1
Kent
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor