Message280661
On Sat, Nov 12, 2016 at 08:23:45AM +0000, Raymond Hettinger wrote:
> I can't even dream up any scenarios where
> ``operator.subscript[3:7:2]`` would be better than
> ``slice(3, 7, 2)``.
For that specific example, I completely agree. But I think that in
general ``slice[::-1]`` is better than either the current alternative
``slice(None, None, -1)`` or the proposed ``operator.subscript[::-1]``.
And there's no comparison once you get to multi-dimensional slices:
s = slice[::-1, 1:, 1::2]
spam[s] + eggs[s]
versus:
s = slice(slice(None, None, -1), slice(1, None), slice(1, None, 2))
spam[s] + eggs[s]
Even simple examples look nice in slice syntax:
slice[3:7:2]
I had completely forgotten about this feature request, but
coincidentally re-suggested it on the Python-Ideas mailing
list earlier today:
https://mail.python.org/pipermail/python-ideas/2016-November/043630.html
The downside is that beginners who are still learning Python's
syntax may try writing:
slice(::-1)
by mistake. Nevertheless, it seems to me that the advantage to more
experienced developers to be able to read and write slice objects using
slice format outweighs the temporary confusion to beginners. (I would
expect that outside of the Numpy community, few beginners use the
slice() object directly, so this would not often affect them.) |
|
Date |
User |
Action |
Args |
2016-11-12 13:48:13 | steven.daprano | set | recipients:
+ steven.daprano, rhettinger, mark.dickinson, taleinat, Arfrever, r.david.murray, python-dev, martin.panter, serhiy.storchaka, yselivanov, josh.r, llllllllll, levkivskyi, abarry |
2016-11-12 13:48:13 | steven.daprano | link | issue24379 messages |
2016-11-12 13:48:12 | steven.daprano | create | |
|