# -*- coding: utf-8 -*- """ Created on Tue Apr 25 15:27:15 2017 @author: buyizhiyou """ ''' 不带参数的装饰器,装饰器在原函数基础上加上了一些额外的功能 ''' def log(fun): def wrapper(*args,**kw): print('call %s () ' % fun.__name__) return fun(*args,**kw) return wrapper @log def hello(): print("hello world") hello() ''' 带参数的装饰器 ''' def log2(text): def dec(fun): def wrapper(*args,**kw): print('%s %s()'%(text,fun.__name__)) return fun(*args,**kw) return wrapper return dec @log2('excute') def hello(): print("hello world") hello()