装饰器相当于一个装饰,不修改函数原本内容,只是增添内容
def my_decorator(func):
def warpper():
print("有函数要执行了")
func()
print("有函数执行完毕")
return warpper
@my_decorator
def say_hello():
print("hello")
say_hello()
相当于
def my_decorator(func):
def warpper():
print("有函数要执行了")
func()
print("有函数执行完毕")
return warpper
def say_hello():
print("hello")
my_decorator(say_hello)()
标签:python,特性,hello,say,decorator,func,print,装饰,def
From: https://www.cnblogs.com/breeze666/p/18125087