类的装饰器
作者:互联网
def deco(func): print('======') return func @deco #--->test=deco(test) def test(): print('test----') test() #result # ====== # test---- @deco #------>Foo=deco(Foo) class Foo: pass #======基本原理
def deco(obj): obj.x=1 obj.y=2 obj.z=3 return obj @deco #------>Foo=deco(Foo) class Foo: pass print(Foo.__dict__) # {'__module__': '__main__', '__dict__': <attribute '__dict__' of 'Foo' objects>, '__weakref__': <attribute '__weakref__' of 'Foo' objects>, '__doc__': None, 'x': 1, 'y': 2, 'z': 3}View Code
标签:__,deco,obj,print,test,Foo,装饰 来源: https://www.cnblogs.com/wuweixiong/p/10633388.html