装饰器

#类装饰器
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

 

posted @ 2020-07-17 13:55  秋夜花开  阅读(97)  评论(0编辑  收藏  举报