装饰器
#类装饰器 class Foo(object): def __init__(self, func): self._func = func def __call__(self): print ('class decorator runing') self._func() print ('class decorator ending') @Foo def bar(): print ('bar') bar()
运行结果
class decorator runing bar class decorator ending
一个刚开始接触互联网滴小白鼠