通过反射找到位置参数的名称
有没有办法找出一个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
1 个回答
12
在Python 2中,inspect.getargspec()
这个函数可以满足你的需求。
但是在Python 3中,这个函数已经不推荐使用了,你应该改用signature
。