通过内省查找位置参数的名称

bra*_*ray 9 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
Run Code Online (Sandbox Code Playgroud)

Sve*_*ach 11

该函数inspect.getargspec()在Python 2中完成了您所需的功能.

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