[Python-ideas] slice.literal notation
Antoine Pitrou
solipsis at pitrou.net
Wed Jun 10 18:20:45 CEST 2015
On Wed, 10 Jun 2015 19:01:49 +0300
Tal Einat <taleinat at gmail.com> wrote:
> >
> >>>> slice.literal[0]
> > 0
> >>>> slice.literal[0, 1]
> > (0, 1)
> >>>> slice.literal[0, 1:]
> > (0, slice(1, None, None)
> >>>> slice.literal[:, ..., ::-1]
> > (slice(None, None, None), Ellipsis, slice(None, None, -1)
> >
> > These examples show that sometimes the subscript notation is much more clear
> > that the non-subscript notation.
Agreed.
> > I believe that while this is trivial, it is very convinient to have on the
> > slice type itself so that it is quickly available. This also prevents
> > everyone from rolling their own version that is accesible in different ways
> > (think Py_RETURN_NONE).
> > Another reason that chose this aproach is that it requires no change to the
> > syntax to support.
>
> In regard with the first suggestion, this has already been mentioned
> on the tracker but is important enough to repeat here: This already
> exists in NumPy as IndexExpression, used via numpy.S_ or
> numpy.index_exp.
Probably, but it looks useful to enough to integrate the standard
library.
Another possible place for it would be the ast module.
Regards
Antoine.
More information about the Python-ideas
mailing list