Example:

import numpy
print numpy.polydiv.__doc__

output:

Returns the quotient and remainder of polynomial division...

While using pydoc:

$ pydoc numpy.polydiv

I get:

numpy.polydiv = polydiv(u, v)
Returns the quotient and remainder of polynomial division...

Is there some available attribute that would allow me to get function declaration part polydiv(u, v) by using python script (without using pydoc/terminal)

有帮助吗?

解决方案

Just in case you weren't aware, you can always use the help function in an interactive session to do the equivalent of what pydoc does.

But to answer your specific question:

The signature of a function object can be obtained using the inspect module:

>>> import numpy, inspect
>>> def sig(func):
...     argspec = inspect.getargspec(func)
...     return func.__name__ + inspect.formatargspec(*argspec)
... 
>>> print sig(numpy.polydiv)
polydiv(u, v)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top