标签:参数 步骤 ret class print str pytho turn int
def w1(func): print(‘装饰器1....‘) def w1_in(): print(‘w1_in.....‘) func() return w1_in def w2(func): print(‘装饰器2.....‘) def w2_in(): print(‘w2_in......‘) func() return w2_in @w1 @w2 def f1(): print(‘f1....‘) f1()
你知道上面的代码执行的步骤吗?.................................................................................
......................................................................................................................................
......................................................................................................................................
......................................................................................................................................
装饰器2.....
装饰器1....
w1_in.....
w2_in......
f1....
带有参数的装饰器:
def w1(func): print(‘装饰器1....‘) def w1_in(a,b): print(‘w1_in.....‘) func(a,b) return w1_in def w2(func): print(‘装饰器2.....‘) def w2_in(a,b): print(‘w2_in......‘) func(a,b) return w2_in @w1 @w2 def f1(a,b): print(‘a=%d,b=%d‘%(a,b)) f1(22,10)
标签:参数 步骤 ret class print str pytho turn int
原文地址:http://www.cnblogs.com/tianboblog/p/7208431.html