python装饰器

来源:互联网 发布:武汉java 开发前景 编辑:程序博客网 时间:2024/06/05 07:21

装饰器就是加了个括号而已吧

def route1(ref):  print('begin route1')  def route2(f):    print('begin route2')    def route3(*args, **kwargs):      print('begin route3')      print(*args, **kwargs)      ret = f(*args, **kwargs)      print('f', f)      print('end route3')      return ret    print('route3', route3)    print('end route2')    return route3  print('route2', route2)  print('end route1')  return route2@route1def f1(rrr):  print(rrr)print(f1)f1('aoeuaaaaaaaaa') #route1(f1)()@route1('ttt')def f2(rrr):  print(rrr)print(f2)print('#########')f2('aoeaoe') #route1('ttt')(f2)()
0 0
原创粉丝点击