Is it possible to overload the [] (__getitem__) operator methods and Python chains using the original memory reference.
Suppose I have a Math class that accepts a list of integers, for example:
class Math(object): def __init__(self, *args, **kwargs): assert(all([isinstance(item, int) for item in list(args)])) self.list = list(args) def add_one(self): for index in range(len(self.list)): self.list[index] += 1
And I want to do something like this:
instance = Math(1,2,3,4,5) instance[2:4].add_one()
After executing this code, instance.list should be [1,2,4,5,5] , is this possible?
I know I can do something like add_one(2,4) , but that is not the style of the API that I would like to have, if possible.
thanks
maraujop
source share