decorate 运行跳出错误,到底错在哪里?
import time
def performance(f):
def fn(*args,**kw):
t1=time.time()
r=f(*args,**kw)
t2=time.time()
print "call %s() in %fs" %(f._name_,(t2-t1))
return r
return fn@performance
def factorial(n):
return reduce(lambda x,y:x*y,range(1,n+1))
print factorial(10)Traceback (most recent call last):
File "E:/learn python/practice4.py", line 14, in <module>
print factorial(10)
File "E:/learn python/practice4.py", line 7, in fn
print "call %s() in %fs" %(f._name_,(t2-t1))
AttributeError: 'function' object has no attribute '_name_'