Search code examples
pythonintrospection

List all function argument names (no docu)


I am a relative beginner in Python and I am trying to use it to run some not-well-documented code. My question is, how can I get a list of possible arguments of a function or a class constructor using interactive shell, for example. Ideally, I would like to have something like dir(), but it should list not class members, but possible argument's names of a function.

If it is not possible, is there any other way to infer function arguments without looking inside the code?


Solution

  • You want inspect.getargspec:

    >>> import inspect
    >>> def foo(bar, baz):
    ...     pass
    ... 
    >>> inspect.getargspec(foo)
    ArgSpec(args=['bar', 'baz'], varargs=None, keywords=None, defaults=None)