[Python-ideas] Using * in indexes

Mike Graham mikegraham at gmail.com
Tue Sep 14 15:54:49 CEST 2010


On Tue, Sep 14, 2010 at 12:16 AM, Greg Ewing
<greg.ewing at canterbury.ac.nz> wrote:
> 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, :]

If in indexes, why not when making other tuples?

Mike



More information about the Python-ideas mailing list