Tal Einat added the comment: (This should probably be discussed on the Python Ideas mailing list...)
I definitely like the idea of being able to construct slices etc. using "[]" syntax. I think this should be considered even if it is decided not to change the repr() of slices. An important note here is that this is about more than slices: $ python3 Python 3.4.2 (default, Feb 23 2015, 21:16:28) [GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> class A: ... def __getitem__(self, *args): ... print(repr(args)) ... >>> a = A() >>> a[0] (0,) >>> a[0:1] (slice(0, 1, None),) >>> a[0:1, ..., 1:2] ((slice(0, 1, None), Ellipsis, slice(1, 2, None)),) >>> a[0:1, 2] ((slice(0, 1, None), 2),) Indeed, Joe's suggested slice.literal supports all of this, but we can't just modify slice to handle all of these cases. What I'm missing is a way to use such an object to actually index/slice something. The only way I can currently think of is using a.__getitem__(), but that's quite ugly IMO. ---------- nosy: +taleinat _______________________________________ Python tracker <[email protected]> <http://bugs.python.org/issue24379> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
