[Python-ideas] Using * in indexes

Greg Ewing greg.ewing at canterbury.ac.nz
Tue Sep 14 06:16:37 CEST 2010


I just found myself writing a method like this:

   def __getitem__(self, index):
     return self.data[(Ellipsis,) + index + (slice(),)]

I would have liked to write it like this:

    self.data[..., index, :]

because that would make it much easier to see what's
being done. However, that won't work if index is itself
a tuple of index elements.

So I'd like to be able to do this:

    self.data[..., *index, :]

-- 
Greg



More information about the Python-ideas mailing list