Proposed PEP: New style indexing, was Re: Bug in slice type
Steven Bethard
steven.bethard at gmail.com
Sat Aug 20 17:33:22 EDT 2005
Bryan Olson wrote:
> Steven Bethard wrote:
> > Well, I couldn't find where the general semantics of a negative stride
> > index are defined, but for sequences at least[1]:
> >
> > "The slice of s from i to j with step k is defined as the sequence of
> > items with index x = i + n*k such that 0 <= n < (j-i)/k."
> >
> > This seems to contradict list behavior though. [...]
>
> The conclusion is inescapable: Python's handling of negative
> subscripts is a wart.
I'm not sure I'd go that far. Note that my confusion above was the
order of combination of points (3) and (5) on the page quoted above[1].
I think the problem is not the subscript handling so much as the
documentation thereof. I posted a message about this [2], and a
documentation patch based on that message [3].
[1] http://docs.python.org/lib/typesseq.html
[2] http://mail.python.org/pipermail/python-list/2005-August/295260.html
[3] http://www.python.org/sf/1265100
> Suppose instead of using semicolons as the PPEP proposes, we use
> commas, as in:
>
> sequence[start, stop, step]
This definitely won't work. This is already valid syntax, and is used
heavily by the numarray/numeric folks.
STeVe
More information about the Python-list
mailing list