目瞪狗呆啊,装饰器是不是外星产物啊,根本不懂啊!!
def new_fn(f): def fn(x): print ('call' , f.__name__ + '()') return f(x) return fn @new_fn def f1(x): return x*2 f1=new_fn(f1) print (f1(5))
为什么这里打印的是
call fn() call f1() 10
接着来加两行:
def new_fn(f): def fn(x): print ('call' , f.__name__ + '()') return f(x) return fn @new_fn def f1(x): return x*2 f1=new_fn(f1) print (f1(5)) g1=new_fn(f1) print (g1(5))
天啦噜它打印的是这样的
call fn() call f1() 10 call fn() call fn() call f1() 10
求外星大牛解释一下