Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print out list of function parameters in Python

Tags:

python

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"]
like image 877
oneself Avatar asked Nov 28 '22 05:11

oneself


2 Answers

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

like image 35
S.Lott Avatar answered Nov 30 '22 18:11

S.Lott


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.

like image 171
DzinX Avatar answered Nov 30 '22 19:11

DzinX