문제

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