for loop: range() result has too many items
Peng Yu
pengyu.ut at gmail.com
Tue Oct 13 17:17:58 EDT 2009
Hi,
The following code does not run because range() does not accept a big
number. Is there a way to make the code work. I'm wondering if there
is a way to write a for-loop in python similar to that of C style.
for(int i = 0; i < a_big_number; ++ i)
Regards,
Peng
$ cat for_loop.py
import sys
def foo():
for i in range(sys.maxint):
if i % 100 == 0:
print i
foo()
$ python for_loop.py
Traceback (most recent call last):
File "for_loop.py", line 8, in <module>
foo()
File "for_loop.py", line 4, in foo
for i in range(sys.maxint):
OverflowError: range() result has too many items
More information about the Python-list
mailing list