猿问

为什么我的不行啊

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 <module>

    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_'

>>> 


慕粉3729768
浏览 1319回答 1
1回答

小胖纸

__name__,不是_name_
随时随地看视频慕课网APP

相关分类

Python
我要回答