在python中使用inspect模块对函数的参数进行遍历,具体方法如下:
import inspect #导入inspect模块def f(a,b,c):argspec=inspect.getargvalues(inspect.currentframe())return argspecf(1,2,3)ArgInfo(args=['a', 'b', 'c'], varargs=None, keywords=None, locals={'a': 1, 'c': 3, 'b': 2})
import inspect #导入inspect模块
def f(a,b,c):
argspec=inspect.getargvalues(inspect.currentframe())
return argspec
f(1,2,3)
ArgInfo(args=['a', 'b', 'c'], varargs=None, keywords=None, locals={'a': 1, 'c': 3, 'b': 2})