Python 3: range objects cannot be sliced

Fuzzyman fuzzyman at gmail.com
Fri Jan 16 13:02:26 EST 2009


On Jan 16, 5:45 pm, Alan G Isaac <alan.is... at gmail.com> wrote:
> Is the behavior below expected? Documented?
> (The error msg is misleading.)
> Thanks,
> Alan Isaac
>
>  >>> x = range(20)
>  >>> s = slice(None,None,2)
>  >>> x[s]
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
> TypeError: sequence index must be integer, not 'slice'

Well, it has the same behaviour as the iterator returned by xrange in
Python 2.X - so expected I guess. The error message is also the same
in Python 2.X.

Michael Foord
--
http://www.ironpythoninaction.com/



More information about the Python-list mailing list