AW: Problem with Python xrange

Christian Neumann mail at neumann-rosenheim.de
Sun Jun 6 16:46:33 EDT 2004


Hello Robert! 

Sorry. It was my mistake!

I read over this: "They don't support slicing"

Thank you very much indeed!

Christian Neumann

-----Ursprüngliche Nachricht-----
Von: Robert Brewer [mailto:fumanchu at amor.org] 
Gesendet: Sonntag, 6. Juni 2004 22:04
An: Christian Neumann; python-list at python.org
Betreff: RE: Problem with Python xrange

Christian Neumann wrote:

> I use Python 2.3.4 (final) and i think there is a bug
> in the built-in function xrange().
>  
> An example is:
>  
> x = xrange(2, 11, 2)  ## [2, 4, 6, 8, 10]
>  
> I get an TypeError if i use it with SliceType:
> 
> x[1:4]  ## It should be return an xrange object with length 3
>  
> Here is the error message: 
>  
> "TypeError: sequence index must be integer".

Hm. I never noticed this either:

>>> x = xrange(2, 11, 2)
>>> x
xrange(2, 12, 2)

But back to your question. Anytime you use the word "should" in a bug
report, you might guess it's really a feature request, not a bug. ;)
Simply put, the "xrange type" doesn't support slicing like that. From
the docs: http://docs.python.org/lib/typesseq.html

"Xrange objects are similar to buffers in that there is no specific
syntax to create them, but they are created using the xrange() function.
They don't support slicing, concatenation or repetition, and using in,
not in, min() or max() on them is inefficient."


Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org





More information about the Python-list mailing list