第一题:
def decorator(func): def warps(*args,**kw): print("begin call") a = func(*args,**kw) print("end call") return a return warps @decorator def now(): print("haha") now()
第二题 装饰器和函数代码
def log(text): def decorator(func): def warps(*args,**kw): print("begin call") print("%s : %s" % (text,func.__name__)) a = func(*args,**kw) print("end call") return a return warps if isinstance(text,str): return decorator func = text text = "excute" return decorator(func) @log("excited") def now(): print("haha") now()
第二种
def log(text): def decorator(func): def warps(*args,**kw): print("begin call") print("%s : %s" % (text,func.__name__)) a = func(*args,**kw) print("end call") return a return warps if isinstance(text,str): return decorator func = text text = "excute" return decorator(func) @log def now(): print("haha") now()
请问为什么要写 text = "excute" 感觉text 已经没有用了啊
求教 func = text text = "excute" return decorator(func) 是什么意思
Sign in to make a reply
90qn
第一题:
第二题 装饰器和函数代码
第二种