import time
from functools import reduce
def log(f):
def fn(x):
print ('call' + f._name_ +'()...')
return f(x)
return fn
@log
def fac(n):
return reduce(lambda x,y:x*y,range(1,n+1))
print fac(2)
Traceback (most recent call last):
File "C:\Users\gege\Desktop\aa.py", line 11, in
print fac(2)
File "C:\Users\gege\Desktop\aa.py", line 5, in fn
print ('call' + f._name_ +'()...')
AttributeError: 'function' object has no attribute '_name_'
>>> |