Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generator exps fail with large value of range #40874

Closed
mrmoose mannequin opened this issue Sep 6, 2004 · 2 comments
Closed

Generator exps fail with large value of range #40874

mrmoose mannequin opened this issue Sep 6, 2004 · 2 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@mrmoose
Copy link
Mannequin

mrmoose mannequin commented Sep 6, 2004

BPO 1022912
Nosy @rhettinger

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 = None
closed_at = <Date 2004-09-06.07:25:24.000>
created_at = <Date 2004-09-06.07:19:35.000>
labels = ['interpreter-core', 'invalid']
title = 'Generator exps fail with large value of range'
updated_at = <Date 2004-09-06.07:25:24.000>
user = 'https://bugs.python.org/mrmoose'

bugs.python.org fields:

activity = <Date 2004-09-06.07:25:24.000>
actor = 'rhettinger'
assignee = 'none'
closed = True
closed_date = None
closer = None
components = ['Interpreter Core']
creation = <Date 2004-09-06.07:19:35.000>
creator = 'mr_moose'
dependencies = []
files = []
hgrepos = []
issue_num = 1022912
keywords = []
message_count = 2.0
messages = ['22368', '22369']
nosy_count = 2.0
nosy_names = ['rhettinger', 'mr_moose']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue1022912'
versions = ['Python 2.4']

@mrmoose
Copy link
Mannequin Author

mrmoose mannequin commented Sep 6, 2004

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(a for a in range(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 in range(1, 123))
7503
>>> sum(a for a in range(1, 999999999999999))
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
OverflowError: range() result has too many items
>>> 

*********** End of output


@mrmoose mrmoose mannequin closed this as completed Sep 6, 2004
@mrmoose mrmoose mannequin added invalid interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Sep 6, 2004
@rhettinger
Copy link
Contributor

Logged In: YES
user_id=80475

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 ;-)

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)
Projects
None yet
Development

No branches or pull requests

1 participant