You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2004-09-06.07:25:24.000>created_at=<Date2004-09-06.07:19:35.000>labels= ['interpreter-core', 'invalid']
title='Generator exps fail with large value of range'updated_at=<Date2004-09-06.07:25:24.000>user='https://bugs.python.org/mrmoose'
My platform - Mepis Linux, kernel 2.6.4 , Pentium III
I tested generator expressions by using the following
statement (which finds the sum of a range of numbers) -
sum(aforainrange(1, 123))
As can be seen in the output below, this works fine
for small values of a. However, it gives an
OverflowError for large values of a.
********* Start of output
Python 2.4a3 (#1, Sep 5 2004, 15:03:34)
[GCC 3.3.3 (Debian 20040429)] on linux2
Type "help", "copyright", "credits" or "license" for
more information.
>>> sum(a for a inrange(1, 123))
7503
>>> sum(a for a inrange(1, 999999999999999))
Traceback (most recent call last):
File "<stdin>", line 1, in ?
OverflowError: range() result has too many items
>>>
That is an error message from range(), not from genexps.
To see that, try range(9999999999999) by itself.
Even if range could process numbers that big, you wouldn't
have enough memory to holding the resulting list. For what
you're trying to do, use xrange() to save memory.
Also remember that using large numbers will result in that
many iterations. If the number is too large, you may grow
old before the computation completes ;-)
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: