[Python-Dev] RE: slice objects

David Ascher dascher@mindspring.com
Thu, 3 Feb 2000 12:14:26 -0800


> (While we're on the topic: is there an easy way to construct a slice
> like 3:10, pass it around as a variable, and later use it to index an
> arbitrary sequence?)

Sort of.  Slice objects can be created with the slice builtin.
slice(1,10,2) is meant to be equivalent to 1:10:2, but only NumPy knows how
to deal with slice objects in the getitem slot (use None to express
'omission' of an index).  It's on the TODO list for 1.7 at this point,
although if someone submits a working patch to 1.6, who knows...  JPython
does it right, I believe.

--david