[Python-Dev] Indexing builtin sequences with objects which supply __int__

Guido van Rossum guido@python.org
Fri, 21 Jun 2002 09:59:50 -0400

> I liked MvL's __index__ method. I understand your hesitancy. It's
> pretty tough exploring new features side-by-side the "version
> fatigue" thread :)


> >What's your use case?  Why do you need this?

> This might settle it :) Numeric/numarray arrays are sometimes used in 
> reduction operations (e.g. max) which eliminate one dimension. Sometimes 
> the result is a zero dimensional array, which is currently converted to 
> a Python scalar in both Numeric and numarray. The conversion to scalar 
> enables integer zero dimensional results to be used as indices, but 
> causes other problems since any auxilliary information in the array 
> (e.g. type = Int8) is lost. Adding some form of implicit conversion to 
> index value might permit us to retain zero dimensional objects as arrays.

But when you're indexing Numeric/numarray arrays, you have full
control over the interpretation of indices, so you can do this
yourself.  Do you really need to be able to index Python sequences
(lists, tuples) with your 0-dimensional arrays?  Could you live with
having to call int() in those cases?

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