(x)range( 40000000000, 40000000001 )

Discussion in 'Python' started by Chris Connett, Jun 29, 2003.

  1. 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.
     
    Chris Connett, Jun 29, 2003
    #1
    1. Advertising

  2. > 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
     
    Raymond Hettinger, Jun 29, 2003
    #2
    1. Advertising

  3. Chris Connett

    Aahz Guest

    In article <3eff347f$>,
    Chris Connett <> 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 () <*> http://www.pythoncraft.com/

    Usenet is not a democracy. It is a weird cross between an anarchy and a
    dictatorship.
     
    Aahz, Jun 30, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    46
    Views:
    992
    Antoon Pardon
    Jul 25, 2006
  2. Lambda
    Replies:
    2
    Views:
    420
    James Kanze
    Jul 16, 2008
  3. Tomoyuki Kosimizu

    Range does not take an Range object.

    Tomoyuki Kosimizu, Nov 25, 2003, in forum: Ruby
    Replies:
    3
    Views:
    162
    Tomoyuki Kosimizu
    Nov 27, 2003
  4. David Bird
    Replies:
    1
    Views:
    229
    Tiago Macedo
    Jun 23, 2008
  5. Joey Zhou
    Replies:
    5
    Views:
    243
    Joey Zhou
    Apr 15, 2011
Loading...

Share This Page