Is there anything internal in python that handles arguments passed in __getitem_
_different ways and automatically converts constructs start:stop:stepto slices?
It demonstrates what I mean
class ExampleClass(object):
def __getitem__(self, *args):
return args
def __call__(self, *args):
return args
def randomMethod(self, *args):
return args
a = ExampleClass()
print a[3:7:2, 1:11:2]
print a.randomMethod(3:7:2, 1:11:2)
print a(3:7:2, 1:11:2)
print a.randomMethod(slice(3,7,2), slice(1,11,2))
print a(slice(3,7,2), slice(1,11,2))
Is the interpreter just looking for instances start:stop:stepinside []and replacing them with slice(start, stop, step)? The documentation just says:
The parenthesis (index) designation uses slice objects inside
Is this one of the internal bits of python that I cannot change the behavior? Is it possible for other functions to take slice objects, cut out the sash start:stop:step? *
* , python ?, , . , , - start:stop:step, .
:
, [...] tuple, [*args] → __getitem__(args).
class ExampleClass2(object):
def __getitem__(self, arg):
return arg
def __call__(self, arg):
return arg
b = ExampleClass2()
print b["argument 1", 2:4:6,3]
print b(slice(3,7,2), slice(1,11,2))