python 装饰器
import time def decorator(func): def wrapper(): print time.time() func() return wrapper def f1(): print('xxxxxx') f= decorator(f1) f()
import time def decorator(func): def wrapper(): print time.time() func() return wrapper @decorator def f1(): print('xxxxxx') f1()
import time def decorator(func): def wrapper(name): print time.time() func(name) return wrapper @decorator def f1(name): print('xxxxxx'+name) f1('eeeee')
import time def decorator(func): def wrapper(*args): print time.time() func(*args) return wrapper @decorator def f2(n,m): print('xxxxxx'+n+m) f2(1,3)
import time def decorator(func): def wrapper(*args,**kw): print time.time() func(*args,**kw) return wrapper @decorator def f3(n,m,**kw): print('xxxxxx'+n+m) print(kw) f3(1,3,n=2,e=3)