python Traceback (most recent call last):

>>> import time
>>> def performance(f):
def fn(*args, **kw):
t1=time.time()
result=f(*args, **kw)
t2=time.time()
print ('call'+f._name_+'()...',str(t2-t1))
return result
return fn

>>> @performance
def factotial(n):
return reduce(lambda x,y:x*y,range(1,n+1))

>>> print factotial(10)

Traceback (most recent call last):
File "<pyshell#43>", line 1, in <module>
print factotial(10)
File "<pyshell#40>", line 6, in fn
print ('call'+f._name_+'()...',str(t2-t1))
AttributeError: 'function' object has no attribute '_name_'
请问各位大神,哪里出的问题

第1个回答  2017-06-14
两个下划线
f.__name__
所有对象的私有变量或者方法,都可以通过dir()看。。你用dir查一下就知道了本回答被网友采纳
相似回答