python - 通过内省(introspection)查找位置参数的名称

标签 python

有没有办法找出 python 函数的位置参数的名称?

def foo(arg1, arg2):
  pass

f=foo
# How do I find out want the 1st argument to f is called? I want 'arg1' as an answer

最佳答案

函数inspect.getargspec()在 Python 2 中做你需要的。

在 Python 3 中,这已被弃用,您应该改为使用 signature .

关于python - 通过内省(introspection)查找位置参数的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6255284/

相关文章:

python - ElementTree XML 解析和 urllib2.urlopen

python - 在 windows 中使用 anaconda 安装 tensorflow

python - 使用 Pygame, Python 3 Blitting 非矩形 Sprite

python - 如何使用字典创建动态类名?

python - 如何提高 Python 中不平衡数据集的精度和召回率

python - 查找列表的最大值/最小值时管理空列表/无效输入(Python)

python - 执行 PySpark 代码时遇到 Py4JJavaError

python - 似乎无法让 Python、Peewee、pymysql 和 MySql 数据库正常工作,没有 'returning_clause' 错误

python - Django unittest 只读测试数据库

python - python ctypes中的多维char数组(字符串数组)