Why can't slice use non-int. indices?
Michael Hudson
mwh at python.net
Fri Jun 1 08:50:14 EDT 2001
"Ben Wolfson" <wolfson at uchicago.edu> writes:
> 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?
Because the sq_item & sq_slice methods in the PySequenceMethod struct
in object.h is declared as taking ints rather than PyObject*s. This
is probably wrong, but it's hard to see how to fix it without breaking
backwards compatibility.
Cheers,
M.
--
GAG: I think this is perfectly normal behaviour for a Vogon. ...
VOGON: That is exactly what you always say.
GAG: Well, I think that is probably perfectly normal behaviour for a
psychiatrist. -- The Hitch-Hikers Guide to the Galaxy, Episode 9
More information about the Python-list
mailing list