Handling slices

Alexander Schmolck a.schmolck at gmx.net
Mon Apr 7 10:31:48 EDT 2003


Jp Calderone <exarkun at intarweb.us> writes:

> On Mon, Apr 07, 2003 at 03:54:17AM +0100, Alexander Schmolck wrote:
> > [snip]
> > 
> > Here is a simple example:
> > 
> > class SliceMaker:
> >     """Convinience class to make slices."""
> >     def __getitem__(self, a): return a
> > 
> 
>   It may be worth noting that this is essentially the slice() builtin.

Not quite. The key is "Convinience" (even if misspelled :) :

 SliceMaker()[3:10:-1, NewAxis, ::-2, 0]

vs:

 (slice(3, 10, -1), None, slice(None, None, -2), 0)

I find the first much easier to parse and write correctly (the false analogy
between slice and range doesn't help).

alex




More information about the Python-list mailing list