4

Is there a way to print out a function's parameter list? For example:

def func(a, b, c):
  pass

print_func_parametes(func)

Which will produce something like:

["a", "b", "c"]

3 Answers 3

17

Use the inspect module.

>>> import inspect
>>> inspect.getargspec(func)
(['a', 'b', 'c'], None, None, None)

The first part of returned tuple is what you're looking for.

Sign up to request clarification or add additional context in comments.

Comments

6

Read the source. Seriously. Python programs and libraries are provided as source. You can read the source.

1 Comment

Unless the O.P. is writing some code analysis/development tool, I am guessing that whatever they need it for will end in disaster.
2

You might also try the built-in help() function, which will provide you not only with a list of the named parameters, but also a description of func() if you provided a docstring:

>>> def func(a, b, c):
...     """do x to a,b,c and return the result"""
...     pass
... 
>>> help(func)

gives you

    
Help on function func in module __main__:

func(a, b, c)
    do x to a,b,c and return the result

Most modules are provided with at least some sort of built-in documentation.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.