# 带参数的装饰器
def startEnd(fun):
def wraper(name):
print("!!!!!!!!!!!!start!!!!!!!!!")
fun(name)
print("!!!!!!!!!!!!!end!!!!!!!!!")
return wraper
# 返回值是wraper函数
# hello()相当于执行wraper()
@startEnd
def hello(name):
print("hello {0}".format(name))
hello("boy")
# 在不改变代码的情况下,给现有的函数增加新的功能
# 装饰器通过@进行使用,相当于把hello()函数作为参数
# @startEnd 相当于 hello = startEnd(hello())
# 当调用hello()的时候,就相当于调用了startEnd(hello())
# 装饰器其实就是要你的内存地址
# 重新给你封装新的内存 地址。
# 你执行的时候是执行新的内存地址
# a = hello
# a() 相当于hello()
# a = startEnd(hello)
# a = hello 核心
def author(mm):
def hello(fun):
def preHello(name):
print("This author is {0}".format(mm))
print("###########start###