bradtgmurray bradtgmurray - 8 days ago 5
Python Question

Find names of positional arguments through introspection

Is there a way to figure out the names of the positional arguments to a python function?

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

Answer

The function inspect.getargspec() does what you need in Python 2.

In Python 3, this has been deprecated, and you should instead use signature.

Comments