#装饰器(前) def outer(func): def inner(): print("hello") print("hello") print("hello") return func() return inner @outer def f1(): print("F1") f1()
#装饰器(后) def outer(func): def inner(): print("hello") print("hello") print("hello") r= func() print(‘CCC‘) print(‘CCC‘) print(‘CCC‘) return r return inner @outer def f1(): print("F1") f1()
上面是没有参数的,来两个有参数的
#装饰器(后) def outer(func): def inner(a1,a2): print("hello") print("hello") print("hello") r= func(a1,a2) print(‘CCC‘) print(‘CCC‘) print(‘CCC‘) return r return inner @outer def f1(a1,a2): print("F1") return a1+a2 print(f1(1,2))
原文:http://www.cnblogs.com/youmingkuang/p/7533486.html