装饰器
Posted celebrator
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了装饰器相关的知识,希望对你有一定的参考价值。
from functools import wraps Flag=True def age(flag): def war(c): def inner(*arg,**args): ret=None if(flag): print("abc") ret=c(*arg,**args) print("def") else: ret=c(*arg,**args) return ret return inner return war def sex(flag): def war(func): def inner(*arg,**args): ret = None if (flag): print("abc1") ret = func(*arg, **args) print("def1") else: ret = func(*arg, **args) return ret return inner return war @sex(Flag) @age(Flag) def cat(s): print("adsfasdf"+s) return 1 int= cat("ddddddddddddddddd") print(int)
运行结果:
abc1
abc
adsfasdfddddddddddddddddd
def
def1
1
以上是关于装饰器的主要内容,如果未能解决你的问题,请参考以下文章