1. 程式人生 > >一個簡單的裝飾器

一個簡單的裝飾器

請編寫一個decorator,能在函式呼叫的前後打印出'begin call'和'end call'的日誌。

def log(func):
    def wrapper(*args,**kw):
        print ('begin call')
        func(*args,**kw)
        print ('end call')
    return wrapper

@log
def f():
    print ('this is a app!')

f()

輸出結果:
begin call
this is a app!
end call