[Python-Dev] PEP for adding an sq_index slot so that any object, a or b, can be used in X[a:b] notation (original) (raw)

Alex Martelli aleaxit at gmail.com
Fri Feb 10 02:26:45 CET 2006


On 2/9/06, Travis E. Oliphant <oliphant.travis at ieee.org> wrote: ...

The patch adds a new API function int PyObjectAsIndex(obj).

This was not specifically in the PEP but probably should be. The name could also be PyNumberAsIndex(obj) but I was following the nbnonzero slot example to help write the code.

Shouldn't that new API function (whatever its name) also be somehow exposed for easy access from Python code? I realize new builtins are unpopular, so a builtin 'asindex' might not be appropriate, but perhaps operator.asindex might be. My main point is that I don't think we want every Python-coded sequence to have to call x.index() instead.

Alex



More information about the Python-Dev mailing list