TIMEX
TIMEX

Reputation: 272452

How do I print out which arguments a Python function requires/allows?

Suppose I have a function and I want to print out the arguments it accepts. How can I do this?

Upvotes: 3

Views: 478

Answers (4)

S.Lott
S.Lott

Reputation: 392060

The help function does this.

All you have to do is put in docstrings for your functions.

Upvotes: 0

Boris Gorelik
Boris Gorelik

Reputation: 31817

if you use IPython (as you absolutely should), use

foo?

to see the documentation, including what the function expects, and:

foo??

to see the above documentation plus the source code (if available)

Upvotes: -1

doug
doug

Reputation: 70098

I see that someone has already offered the answer i had in mind, so i'll suggest a purely practical one. IDLE will give you a function's parameters as a 'tooltip'.

This should be enabled by default; the tooltip will appear just after you type the function name and the left parenthesis.

To do this, IDLE just accesses the function's doc string, so it will show the tooltip for any python function--standard library, third-party library, or even a function you've created earlier and is in a namespace accessible to IDLE.

Obviously, this is works only when you are working in interactive mode in IDLE, though it does have the advantage of not requiring an additional function call.

Upvotes: 2

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799570

Use inspect.getargspec() to find out.

Upvotes: 6

Related Questions