I'm looking for a pythonic solution on how to store a method which is called on an object right inside the object.
Because in python, if I want to catch for example the abs()
method, I will overload this operator like:
Catcher(object):
def __abs__(self):
self.function = abs
c = Catcher()
abs(c) # Now c.function stores 'abs' as it was called on c
If I want to catch a function, which have an other attribute in it, for example pow()
, I'm going to use this:
Catcher(object):
def __pow__(self, value):
self.function = pow
self.value = value
c = Catcher()
c ** 2 # Now c.function stores 'pow', and c.value stores '2'
Now, what I'm looking for is a general solution, to catch and store any kind of function called on Catcher
, without implementing all overloads, and other cases. And as You can see, I also want to store the values (maybe in a list, if there is more than one of them?) which are the attributes of a method.
Thanks in advance!