装饰器 | 参数 |demo ---- ====== 不带参数的装饰器 ====== def dec(fun): def _fun(*arg,**args): print "pre" print args res=fun(*arg) print "after" return res return _fun @dec def a(i,j,a='0'): print 'run fun a' return i+j print a(3,4,a='b') ====== 带参数的装饰器 ====== def decc(i): def dec(fun): def _fun(*arg,**args): print "pre" print args,i res=fun(*arg) print "after" return res return _fun return dec @decc(100) def b(a,b,c='aa'): return a+b print b(1,2,a='aaa')