Allowing zero-dimensional subscripts

spam.noam at gmail.com spam.noam at gmail.com
Fri Jun 9 09:11:05 EDT 2006


Hello,

Fredrik Lundh wrote:
> (but should it really result in an empty tuple?  wouldn't None be a bit
> more Pythonic?)

I don't think it would. First of all, x[()] already has the desired
meaning in numpy. But I think it's the right thing - if you think of
what's inside the brackets as a list of subscripts, one for each
dimension, which is translated to a call to __getitem__ or __setitem__
with a tuple of objects representing the subscripts, then an empty
tuple is what you want to represent no subscripts.

Of course, one item without a comma doesn't make a tuple, but I see
this as the special case - just like parentheses with any number of
commas are interpreted as tuples, except for parentheses with one item
without a comma.

(By the way, thanks for the tips for posting a PEP - I'll try to do it
quickly.)

Noam




More information about the Python-list mailing list