Python.装饰器

来源:互联网 发布:mac系统格式化u盘 编辑:程序博客网 时间:2024/06/05 19:24
import time

def decorator(func):
def wrapper(*args,**kw):
print(time.time())
func(*args,**kw)
return wrapper

@decorator
def f1(func_name):
print("this is a function "+func_name)


@decorator
def f2(func_name,func_name2):
print("this is a function "+func_name)
print("this is a function "+func_name2)

@decorator
def f3(func_name,func_name2, **kw):
print("this is a function "+func_name)
print("this is a function "+func_name2)
print(kw)


f1('test func')
f2('test func','test func2')
f3('test func','test func2',a=1,b=2,c='123')


1512463591.4760053
this is a function test func
1512463591.4770052
this is a function test func
this is a function test func2
1512463591.4770052
this is a function test func
this is a function test func2
{'a': 1, 'b': 2, 'c': '123'}

原创粉丝点击