[Python-Dev] PEP Proposal: Revised slice objects & lists use slice objects as indexes

Nick Coghlan ncoghlan at gmail.com
Mon Mar 10 16:54:11 CET 2008


Forrest Voight wrote:
>>  I am not sure what you are trying to propose here. The slice object
>>  isn't special, it's just a regular built-in type.
> 
>  The idea is to have slice objects be generators. You could make a
>  slice like 1:10:2 , and that would make a slice object which could be
>  used as a list index. The list would return a list with the
>  corresponding item for every index in the generator. Then, lists could
>  transparently be used as list indexes, or you could supply your own
>  generator instead of a slice object.

You can already pass whatever items you like to __getitem__ for your own 
sequences without even touching the builtin slice(). You can even write 
a decorator to convert slice objects to the relatively arbitrary index 
iterators you appear to favour (I wish you good luck in getting those to 
play well with numpy and the myriad of other C extensions that rely on 
the existing extended slicing semantics, or explaining how they work to 
a Python novice - you're going to need it).

That said, and as Alexandre already pointed out, this thread is 
off-topic for python-dev - please take it to python-ideas to thrash out 
whether or not it has any practical applications, and whether those 
applications (assuming they exist) are even remotely close to compelling 
enough to justify the pain involved in making such a major change to the 
core language.

Regards,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-Dev mailing list