Seek support for new slice syntax PEP.
Colin W.
cjwilliams43 at gmail.com
Sat Dec 19 05:50:10 EST 2009
On 18-Dec-09 23:16 PM, Nobody wrote:
> On Fri, 18 Dec 2009 09:49:26 -0500, Colin W. wrote:
>
>> 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:
>
> > class foo:
> = def __getitem__(self, s):
> = return s
> =
> > x = foo()
> > x[::]
> slice(None, None, None)
> > x[1::2]
> slice(1, None, 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.
>
No, it seems that the implementation is a little different from the doc.
You are right:
*** Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit
(Intel)] on win32. ***
>>> a= range(10)
>>> a[2:8:2]
[2, 4, 6]
>>> a[2::2]
[2, 4, 6, 8]
>>> a[2:None:2]
[2, 4, 6, 8]
>>>
I had expected the last to be rejected, but it fits with the overall
philosophy.
Colin W
More information about the Python-list
mailing list