I'm trying to print out the function's name and arguments that is called by the instance everytime the instance makes a function call
I'm using getattribute method to implement this, my code is below
def __getattribute__(self, attr):
def newfunc(*args, **kwargs):
print( "%r Calling %r with %r %r" % (self, attr, args, kwargs))
return newfunc
The code does print out the function's name and arguments, but the origin method is not executed, since it returns a new function instead of calling the old one.
I did some searchs, like this question, the highest vote in this answer using dict to retrieve the function by it's name in a dictionary, I tried that, but it result in a recursive call.
My question is. is there a way to print out function's name and arguments inside __getattribute__method ?
or is there a way to print out function's name and arguments everytime an instance is calling its method?
Ps. except using decorators, I knew I can use decorator for this, but I don't want to put decorator in front of every method I use