from functools import wraps
'''
#带参函数
def greet_decorator(name):
def decorator(func):
@wraps(func)
def function():
print('包装函数开始执行')
func()
print('包装函数结束执行')
return function
return decorator
@greet_decorator('name')
def hello(msg = 'good'):
print('hello'+msg)
hello()
'''
#带参类
class greet_decoretor():
def __init__(self,name):
self.name = name
def __call__(self,func):
@wraps(func)
def wrap_function(*args,**kwargs):
print('包装函数开始执行')
func(*args,**kwargs)
print('包装函数结束执行')
return wrap_function
@greet_decoretor('name')
def hello():
print('hello')
hello()