[Python-3000] Using range()

Nick Coghlan ncoghlan at gmail.com
Fri Apr 25 06:04:35 CEST 2008


Mark Dickinson wrote:
> On Thu, Apr 24, 2008 at 11:50 AM, Nick Coghlan <ncoghlan at gmail.com 
> <mailto:ncoghlan at gmail.com>> wrote:
> 
>     There's definitely some bugs in this area of the range object code
>     though:
> 
>      >>> x = range(2**33, 2)
>      >>> len(x)
> 
>     0
>      >>> x[0]
>     Traceback (most recent call last):
>      File "<stdin>", line 1, in <module>
>     IndexError: range object index out of range
> 
> 
> Hmm.  I'm not seeing the bug here.  What am I missing?

Eh, brain explosion from typing too late at night. The experiment I 
actually *meant* to try was:

 >>> x = range(0, 2**33, 2)
 >>> len(x)
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
OverflowError: Python int too large to convert to C ssize_t
 >>> x[0]
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
OverflowError: Python int too large to convert to C ssize_t


The error message in the latter case is thoroughly confusing (although 
it is now clearer what is causing it).

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-3000 mailing list