Why can't slice use non-int. indices?

Ben Wolfson wolfson at uchicago.edu
Thu May 31 21:16:05 EDT 2001


In article <3B168CF7.F44777F9 at yahoo.com>, "Paul Winkler"
<slinkp23 at yahoo.com> wrote:

> This is on python 2.1.
> 
>>>> a = []
>>>> a[3:4]
> []
>>>> a[3.2: 4]
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: slice indices must be integers

For that matter, why doesn't this work?

>>> lst = range(10)
>>> slc = slice(2,6)
>>> lst[slc]
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in ?
    lst[slc]
TypeError: sequence index must be integer

Seems like it ought to.

-- 
Barnabas T. Rumjuggler
(23:18:22) Clock zero: everyone I like is a damn freak
[...]
(23:20:05) Clock zero: I put this small piece of adhesive-backed paper
on my knife which reads "this machine kills fascists"



More information about the Python-list mailing list