我有下一个代码
def timer_dec(f):
def wrapper(*args, **kwargs):
t = time.time()
args[0].debug('<{}> start'.format(f.__name__))
res = f(*args, **kwargs)
args[0].debug('<{}> finish'.format(f.__name__))
args[0].debug("Working time for function <%s>: %f" % (f.__name__, time.time() - t))
return res
return wrapper
这很好用:
@timer_dec
class A(object):
pass
但这不起作用:
@timer_dec
class A(object):
pass
class B(A):
pass
TypeError:调用元类基础函数()参数1时出错必须是代码,而不是str
Python版本是2.7