一张图片了解函数修饰器
代码:
import sys def a_new_decorator(a_func): def wrapTheFunction(): print('萨瓦迪卡') print("I am doing some boring work before executing a_func()") a_func() print("I am doing some boring work after executing a_func()") return wrapTheFunction @a_new_decorator def a_function_requiring_decoration(): """Hey you! Decorate me!""" print("I am the function which needs some decoration to " "remove my foul smell") a_function_requiring_decoration()