温馨提示×

python怎么遍历函数的参数

养鱼的猫咪
673
2021-03-08 14:33:47
栏目: 编程语言

python怎么遍历函数的参数

在python中使用inspect模块对函数的参数进行遍历,具体方法如下:

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})

0