对不起,有点混乱。我从http://wiki.python.org/moin/PythonDecoratorLibrary#Easy_Dump_of_Function_Arguments修改了一些代码
def dump_args(func): "This decorator dumps out the arguments passed to a function before calling it" argnames = func.func_pre.co_varnames[:func.func_pre.co_argcount] fname = func.func_name def echo_func(*args,**kwargs): print fname, "(", ', '.join( '%s=%r' % entry for entry in zip(argnames,args[:len(argnames)])+[("args",list(args[len(argnames):]))]+[("kwargs",kwargs)]) +")" return echo_func@dump_argsdef test(a, b = 4, c = 'blah-blah', *args, **kwargs): pass
测试(1、2、3、4、5,d = 6,g = 12.9)
输出:
测试(a = 1,b = 2,c = 3,args = [4,5],kwargs = {‘d’:6,’g’:12.9})
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)