slices: foo[i:j:k] => TypeError

Alex Martelli aleax at aleax.it
Fri Apr 26 18:34:46 EDT 2002


Roman Neuhauser wrote:
        ...
>>>> foo[0:6:2]
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: sequence index must be integer
>>>> 
> 
> What's up? Is that a bug, or am I dumb?

http://www.python.org/dev/doc/devel/lib/typesseq.html only
mentions x:y slices; the x:y:z form is supported only by
Numeric, I believe.  The underlying problem is that list &c
still use the deprecated __getslice__ (or equivalent thereof)
rather than accepting slice objects in __getitem__ (&c for
set and del).


Alex




More information about the Python-list mailing list