不定时更新,不一定适合3.X,但一定适合2.7。
def main(): def decorator_with_params(arg_of_decorator): print arg_of_decorator print '1' def newDecorator(func): print '3' print func.__name__ return func(1,2) print '2' return newDecorator @decorator_with_params("deco_args") def foo(a,b): print 'foo('+str(a)+','+ str(b)+') is called' if __name__ == '__main__': main()
deco_args 1 2 3 foo foo(1,2) is called
原文地址:http://blog.csdn.net/gugugujiawei/article/details/41871563