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