求教为什么这个会报错啊!
import time def performance(unit): t1=time.time() def decorator(f): def fn(*args, **kw): r=f(*args,**kw) t2=time.time() print 'call %s() in %d %s' %f.__name__,t2-t1,unit return r return fn return decorator @performance('ms') def factorial(n): return reduce(lambda x,y: x*y, range(1, n+1)) print factorial(10)
Traceback (most recent call last): File "index.py", line 20, in print factorial(10) File "index.py", line 10, in fn print 'call %s() in %d %s' %f.__name__,t2-t1,unit TypeError: not enough arguments for format string
另外装饰器里为什么一定要插r=f(*args,**kw)这句?而且我不用无参数标识符,用r=f(n)这样的就不行么?