Discuss / Python / 交作业

交作业

Topic source

小小肥民

#1 Created at ... [Delete] [Delete and Lock User]
import functools
def log(fot):  #func or text
    if callable(fot):  #func or not
        @functools.wraps(fot)
        def wrap(*args,**kw):
            print('call %s' % fot.__name__)
            return fot(*args,**kw)
        return wrap
    else:
        def decorator(func):
            @functools.wraps(func)
            def wrap(*args,**kw):
                print('begin call')
                print(fot,func.__name__)
                return func(*args,**kw),'end call'
            return wrap
        return decorator

可以,服气。

多背单词

#3 Created at ... [Delete] [Delete and Lock User]

请问下return text(*args,**kw)

是什么意思啊

为什么callable(fot) = True 的时候,是@log() 而callable(fot) = fault 的时候,又是@log('execute')? 想不明白,为什么括号里有参数的时候不是True的?

代码有点长了


  • 1

Reply