装饰器:
1 >>> def a(func): 2 ... def b(*argv): 3 ... print("in b") 4 ... return func(*argv) 5 ... return b 6 ... 7 >>> def c(a,b): 8 ... print(a**2,b**2) 9 ... 10 >>> c = a(c) 11 >>> c(2,3) 12 in b 13 4 9 14 >>> c.__name__ 15 ‘b‘ 16 >>> @a #装饰器语法糖 = c = a(c) 17 ... def cc(a,b): 18 ... print(a**2,b**2) 19 ... 20 >>> cc(2,3) 21 in b 22 4 9 23 >>> cc.__name__ 24 ‘b‘
原文地址:https://www.cnblogs.com/wjstud/p/8395100.html
时间: 2024-10-09 16:47:55