Frage

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)

War es hilfreich?

Lösung

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)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top