[Python-Dev] non-integer slice indices?

Greg Stein gstein@lyra.org
Fri, 11 Feb 2000 15:32:45 -0800 (PST)


On Fri, 11 Feb 2000, Skip Montanaro wrote:
> Viorel Preoteasa asked on python-help today about supporting slices with
> non-integer indexes, e.g.:
> 
>     foo['a':'abc'] = some_sequence
> 
> Currently the Python interpreter (in the slice_index function of ceval.c)
> enforces integer slice indices.  I won't pretend to provide motivation for
> non-integral slice indices.  Instead, I've CC'd Viorel and will let him
> chime in if he feels the need.  It does seem to me that if the __setslice__
> programmer is willing to do the type checking and provide the semantics of
> "from X to Y" for aribtrary X and Y that the interpreter should let
> non-integer indices pass.

Currently, a person can do the following:

    foo[slice('a','abc')] = some_sequence

In other words, you have to first wrap the thing into a slice object.
Then, it calls the __setitem__ method with the slice object, which can
extract the values using the .start, .stop, and .step attributes.

Now... altering the syntax and semantic restrictions (to make it easier)  
is surely possible, but yah: let's hear some motivations from Viorel.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/