大红色的将军

python 装饰器总结


复制代码
class Dec(object):
    @staticmethod
    def fundec(fun):
        print('1')
        def _fundec(*keys):
            print('2')
            fun(*keys)
            print('3')
        print('4')
        return _fundec
    @staticmethod
    def fundec1(fun):
        print('1-A')
        def _fundec1(*keys):
            print('2-A')
            fun(*keys)
            print('3-A')
        print('4-A')
        return _fundec1

class Myclass(object):
    def __init__(self):
        print("初始化")
    @Dec.fundec1
    @Dec.fundec
    def fun(self):
        print('5')

if __name__ == '__main__':
    ins = Myclass()
    ins.fun()
复制代码

 

 
posted @   欧德派  阅读(121)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示