How to find argument list of a callable?
Andrew Dalke
adalke at mindspring.com
Mon Oct 6 00:09:49 EDT 2003
David Eppstein:
> Suppose I have a callable object x, and suppose for simplicity that it
> doesn't take any *- or **-arguments. How can I get a list of the number
> and names of the arguments of x?
Take a look at the 'inspect' module.
>>> import inspect
>>> def spam(x, y, z=4):
... pass
...
>>> inspect.getargspec(spam)
(['x', 'y', 'z'], None, None, (4,))
>>>
>>> def eggs(a, b, *c, **d):
... pass
...
>>> inspect.getargspec(eggs)
(['a', 'b'], 'c', 'd', None)
>>>
Andrew
dalke at dalkescientific.com
More information about the Python-list
mailing list