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

Guido van Rossum guido at python.org
Fri Feb 10 02:34:22 CET 2006


On 2/9/06, Alex Martelli <aleaxit at gmail.com> wrote:
> 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.

Very good point; this is why we have a PEP discussion phase.

If it's x.__index__(), I think it ought to be operator.index(x). I'm
not sure we need a builtin (also not sure we don't).

I wonder if hasattr(x, "__index__") can be used as the litmus test for
int-ness? (Then int and long should have one that returns self.)

Travis, can you send me additional PEP updates as context or unified
diffs vs. the PEP in SVN? (or against python.org/peps/pep-0357.txt if
you don't want to download the entire PEP directory).

--
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list