Message245070
(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. |
|
Date |
User |
Action |
Args |
2015-06-09 16:00:03 | taleinat | set | recipients:
+ taleinat, rhettinger, mark.dickinson, Arfrever, steven.daprano, serhiy.storchaka, llllllllll |
2015-06-09 16:00:03 | taleinat | set | messageid: <1433865603.02.0.498712031209.issue24379@psf.upfronthosting.co.za> |
2015-06-09 16:00:03 | taleinat | link | issue24379 messages |
2015-06-09 16:00:02 | taleinat | create | |
|