[Python-ideas] str(slice(10)) should return "slice(10)"
Ivan Levkivskyi
levkivskyi at gmail.com
Sat Nov 12 04:37:26 EST 2016
On 12 November 2016 at 10:26, Steven D'Aprano <steve at pearwood.info> wrote:
> But let's make str() of a slice more suggestive of actual slicing, and
> as a bonus, make slices easier to create too.
>
> str(slice(None, None, None)) => "slice[:]"
>
> Let the slice type itself be sliceable, as an alternate constuctor:
>
> slice[:] => returns slice(None)
> slice[start:] => returns slice(start, None)
> slice[:end] => returns slice(None, end)
> slice[start::step] => returns slice(start, None, step)
>
> and so forth. (This probably would require changing the type of slice to
> a new metaclass.)
>
> And then have str() return the compact slice syntax.
>
+1, I like this idea, this is very close to what NumPy does.
I would also mention http://bugs.python.org/issue24379
--
Ivan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20161112/7a660112/attachment-0001.html>
More information about the Python-ideas
mailing list