Bug in slice type

Steven Bethard steven.bethard at gmail.com
Thu Aug 18 10:34:45 EDT 2005


Michael Hudson wrote:
> bryanjugglercryptographer at yahoo.com writes:
>> I'm fine with your favored behavior. What do we do next to get
>> the doc fixed?
> 
> I guess one of us comes up with some less misleading words.  It's not
> totally obvious to me what to do, seeing as the returned values *are*
> indices is a sense, just not the sense in which they are used in
> Python.  Any ideas?

Maybe you could replace:

"these are the start and stop indices and the step or stride length of 
the slice"

with

"these are start, stop and step values suitable for passing to range or 
xrange"


I wanted to say something about what happens with a negative stride, to 
indicate that it produces (9, -1, -2) instead of (-1, -11, -2), but I 
wasn't able to navigate the Python documentation well enough.

Looking at the Language Reference section on the slice type[1] (section 
3.2), I find that "Missing or out-of-bounds indices are handled in a 
manner consistent with regular slices." So I looked for the 
documentation of "regular slices".  My best guess was that this meant 
looking at the Language Reference on slicings[2].  But all I could find 
in this documentation about the "stride" argument was:

"The conversion of a proper slice is a slice object (see section 3.2) 
whose start, stop and step attributes are the values of the expressions 
given as lower bound, upper bound and stride, respectively, substituting 
None for missing expressions."

This feels circular to me.  Can someone help me find where the semantics 
of a negative stride index is defined?


Steve

[1] http://docs.python.org/ref/types.html
[2] http://docs.python.org/ref/slicings.html



More information about the Python-list mailing list