#使用闭包
def decorator(func):
def inner(*args,**kwargs):
print('装饰前')
func()
print('装饰后')
return inner
@decorator
def test():
print('test')
test()
#使用类
class Decorator(object):
def __init__(self, func):
self.__func = func
def __call__(self, *args, **kwargs):
print('装饰前')
self.__func()
print('装饰后')
@Decorator
def test():
print('test')
test()