I am having an object I cant touch, but would like to log the method calls. I don't really understand decorators, but I was wondering if there is a more elegant way to do something like this
import pprint
class myTest(object):
def __init__(self):
self.a = 1
def test(self, **kwargs):
for k, v in kwargs.items():
setattr(self, k, v)
def wrap(o, method, **kwargs):
for k, v in kwargs.items():
print '%s set to %s' %(k, v)
getattr(o, method)(**kwargs)
o = myTest()
d = {'b':2,'c': 3}
wrap(o, 'test', **d)
pprint.pprint(vars(o))
such that I can decorate a regular method call and do it somehow like this:
@mydecorator
o.test(**d)
and would get a similar result. Then I would not have to replace all the method calls in the script