可以赋值给一个变量
可以在其他函数里定义
所以装饰器也是一样,这个例子中自定义了两个装饰器,然后在test()函数上添加了两个装饰器,运行结果正常。
#!/usr/bin/env python
#coding:utf-8
def decorator1(func):
def wrapper():
print 'hello python 之前'
func()
return wrapper
def decorator2(func):
def wrapper():
func()
print 'hello python 之后'
return wrapper
@decorator1
@decorator2
def test():
print 'hello python!'
test() 运行结果:
hello python 之前 hello python! hello python 之后
以上就是Python中如何在一个函数中加入多个装饰器的详细内容,更多请关注Gxl网其它相关文章!
查看更多关于Python中如何在一个函数中加入多个装饰器的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did80720