python装饰器在类中的实现

class Test():
    xx = False

    def __init__(self):
        pass

    def test(func):
        def wrapper(self, *args, **kwargs):
            print(self.xx)
            return func(self, *args, **kwargs)
            
        return wrapper

    @test
    def test_a(self,a,b):
        print(f‘ok,{a} {b}‘)

if __name__==‘__main__‘:
    t=Test()
    t.test_a(‘a‘,‘ab‘)

相关推荐