Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 441
TIMEX Avatar asked Dec 10 '25 06:12

TIMEX


2 Answers

Use inspect.getargspec() to find out.

like image 151
Ignacio Vazquez-Abrams Avatar answered Dec 12 '25 19:12

Ignacio Vazquez-Abrams


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.

like image 40
doug Avatar answered Dec 12 '25 20:12

doug