I want to do some preparatory actions (e.g. logging) before function is called.
For example,
class Test(object):
def float(self, target):
logging.info('Call float() function')
return float(target)
def int(self, target):
logging.info('Call int() function')
return int(target)
t = Test()
a = t.float('123')
b = t.int('123')
However, now I have about 20 functions need to do the same thing. Is there any way I can use 1 function to fit all of them? Something like,
class Test(object):
def __getattr__(self, name):
def wrapper(args):
return func(args) # is there any built-in funciton can get function object?
logging.info('Call %s() function' % name)
return wrapper