30个内置函数及用法: 带key的重点标注:
# def wrapper1(func): # def inner1(*args,**kwargs): # print(‘in wrapper 1,before‘) # ret = func(*args,**kwargs) #qqxing # print(‘in wrapper 1,after‘) # return ret # return inner1 # # def wrapper2(func): #inner1 # def inner2(*args,**kwargs): # print(‘in wrapper 2,before‘) # ret = func(*args,**kwargs) #inner1 # print(‘in wrapper 2,after‘) # return ret # return inner2 # # @wrapper2 # @wrapper1 # def qqxing(): # print(‘qqxing‘) # qqxing() # 多装饰器同时作用时候,会先把调用函数传入离他最近的装饰器,然后该装饰器再传入上一级装饰器中 # def f4(flag): def f2(): def f3(func): def inner(): print(‘123‘) func() return inner return f3 return f2 a = f4(1) @a() #语法糖最多三级, def func(): print(‘hahah‘) func() # 123 # hahah
时间: 2024-10-07 15:19:56