D
Dave Angel
None is perfectly valid as a parameter to a slice. To quote the 2.6.4Colin said:<div class="moz-text-flowed" style="font-family: -moz-fixed">On
No, it seems that the implementation is a little different from the doc.You don't say, but seem to imply that the slice components include
None.
That's how missing components are implemented at the language level:
= def __getitem__(self, s):class foo:
= return s
=slice(1, None, 2)x = foo()
x[::] slice(None, None, None)
x[1::2]
The defaults of zero, sys.maxint and one apply to built-in types, but
nothing forces user-defined types to behave this way.
Or maybe I misunderstood your point.
You are right:
*** Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32
bit (Intel)] on win32. ***I had expected the last to be rejected, but it fits with the overalla= range(10)
a[2:8:2] [2, 4, 6]
a[2::2] [2, 4, 6, 8]
a[2:None:2] [2, 4, 6, 8]
philosophy.
Colin W
</div>
docs, in section 6.6:
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. In
other words, the indices are i, i+k, i+2*k, i+3*k and so on, stopping
when /j/ is reached (but never including /j/). If /i/ or /j/ is greater
than len(s), use len(s). If /i/ or /j/ are omitted or None, they become
“end” values (which end depends on the sign of /k/). Note, /k/ cannot be
zero. If /k/ is None, it is treated like 1.
DaveA