473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

(x)range( 40000000000, 40000000001 )

It seems range and xrange don't like longs that can't be sqeezed into ints:

With Python 2.3b1+:
xrange( 40000000000, 40000000001 ) Traceback (most recent call last):
File "<stdin>", line 1, in ?
OverflowError: long int too large to convert to int range( 40000000000, 40000000001 ) Traceback (most recent call last):
File "<stdin>", line 1, in ?
OverflowError: long int too large to convert to int


Its not a critical problem, and I can find a way around it. It's a just
little disconcerting that (x)range doesn't work with big longs, and it
seems it would not be too difficult to make work.

Jul 18 '05 #1
2 3344
> It seems range and xrange don't like longs that can't be sqeezed into ints:

With Python 2.3b1+:
>>> xrange( 40000000000, 40000000001 ) Traceback (most recent call last):
File "<stdin>", line 1, in ?
OverflowError: long int too large to convert to int >>> range( 40000000000, 40000000001 ) Traceback (most recent call last):
File "<stdin>", line 1, in ?
OverflowError: long int too large to convert to int >>>


Its not a critical problem, and I can find a way around it. It's a just
little disconcerting that (x)range doesn't work with big longs, and it
seems it would not be too difficult to make work.


This is intentional.
xrange() is meant to be a fast, lightweight alternative to range().
It has been given the minimum possible functionality.
Use range() or a generator to meet other needs.
Raymond Hettinger
Jul 18 '05 #2
In article <3e********@buckaroo.cs.rit.edu>,
Chris Connett <ki****************@cs.rit.edu> wrote:

It seems range and xrange don't like longs that can't be sqeezed into ints:

With Python 2.3b1+:
xrange( 40000000000, 40000000001 )Traceback (most recent call last):
File "<stdin>", line 1, in ?
OverflowError: long int too large to convert to int range( 40000000000, 40000000001 )Traceback (most recent call last):
File "<stdin>", line 1, in ?
OverflowError: long int too large to convert to int


The first problem is that range is designed to create a list and the
canonical usage for range is range(N); lists cannot currently have more
than int elements. xrange() could get away with fixing it, but Guido has
decreed that xrange() is a target for deprecation (and will go away in
Python 3.0), so he won't allow any improvements to xrange() in order to
encourage people to use alternatives.
--
Aahz (aa**@pythoncraft.com) <*> http://www.pythoncraft.com/

Usenet is not a democracy. It is a weird cross between an anarchy and a
dictatorship.
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Christopher T King | last post by:
Okay, so this is really two requests in one, and they're both kinda outlandish, but I'm gonna post them nonetheless: I've always thought xrange() to be ugly; it looks to be a lot of typing just...
6
by: Gerrit Holl | last post by:
Hi, why is an xrange object not hashable? I was trying to do something like: comments = { xrange(0, 4): "Few", xrange(4, 10): "Several", xrange(10, 100): "A lot", xrange(100, sys.maxint):...
7
by: Christian Neumann | last post by:
Hello, i have a problem with the built-in function xrange(). Could you by any chance be able to help? I use Python 2.3.4 (final) and i think there is a bug in the built-in
0
by: Christian Neumann | last post by:
Hello Robert! Sorry. It was my mistake! I read over this: "They don't support slicing" Thank you very much indeed! Christian Neumann
35
by: bonono | last post by:
Hi, I am wondering if there is such a thing, as python is moving away from FP functions like dropwhile/takewhile etc.
29
by: Steve R. Hastings | last post by:
When you compile the expression for i in range(1000): pass does Python make an iterator for range(), and then generate the values on the fly? Or does Python actually allocate the list and...
17
by: stdazi | last post by:
Hello! Many times I was suggested to use xrange and range instead of the while constructs, and indeed, they are quite more elegant - but, after calculating the overhead (and losen flexibility)...
3
by: Bas | last post by:
Hi, stupid question, but would it be possible to somehow merge xrange (which is supposed to replace range in py3k) and slice? Both have very similar start, stop and step arguments and both are...
2
by: Joe Goldthwaite | last post by:
I've been playing with Python a bit. Doing little performance benchmarks and working with Psyco. It's been fun and I've been learning a lot. For example, in a previous post, I was looking for a...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.