Introduce :python Decorator is the function expansion of a function from outside the function
def decorate(func):
def wrapper():
print('before demo')
func()
print('after demo')
return wrapper
@decorate
def demo():
print("this is a demo!")
if __name__ == '__main__':
for i in range(10):
demo()
In the above example : By using the decorator decorate For functions demo Expand functions ,wrapper Functions can be used as templates .
Please refer to the link for details :[python Detailed analysis of decorator ]
(https://www.cnblogs.com/yuzhanhong/p/9180212.html)