python 装饰器
Posted AngDH
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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)
以上是关于python 装饰器的主要内容,如果未能解决你的问题,请参考以下文章