Problem with Python xrange
Adonis
adonisv at REMTHISearthlink.net
Sun Jun 6 16:22:18 EDT 2004
"Christian Neumann" <mail at neumann-rosenheim.de> wrote in message
news:mailman.631.1086545766.6949.python-list at python.org...
> 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
> 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".
>
>
>
> Is this really a bug?
>
>
>
> Sincerely yours,
>
>
>
> Christian Neumann
Not a bug...
Adonis
Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> x = range(10)
>>> y = xrange(10)
>>> type(x)
<type 'list'>
>>> type(y)
<type 'xrange'>
>>> help(xrange)
Help on class xrange in module __builtin__:
class xrange(object)
| xrange([start,] stop[, step]) -> xrange object
|
| Like range(), but instead of returning a list, returns an object that
| generates the numbers in the range on demand. For looping, this is
| slightly faster than range() and more memory efficient.
More information about the Python-list
mailing list