Search python docstring - similar to MATLAB `lookup` or Linux` apropos`

Is there a way to search for a module keyword and docstrings function from an interpreter?

Often, when I want to do something in Python, I know that there is a module that does what I want, but I don’t know what it called. I would like to find a way to “name the function or module that makes X” without having “python do X” on Google.

Take the example of “how can I open a URL”? In Linux shell I can try >> apropos open url. In MATLAB I can try >> lookup open url. Both of them will give me lists of functions or modules that include the words "open" and "URL" somewhere in their man or doc page. For instance:

urllib.urlopen   : Create a file-like object for the specified URL to read from.
urllib2.urlopen  : ...
...

I would like something looking for all installed modules, not just the modules that were imported in my current session.

Yes, Google is a great way to search for strings in a Python doc, but latency is a bit high .;)

+5
source share
2 answers

Native support for this comes from pydoc.apropos:

import pydoc
pydoc.apropos('Zip')
# output: zipimport - zipimport provides support for importing Python modules from Zip archives.

Which, as you see, is almost useless. It also stops working when the module cannot be imported, which may mean "always" depending on the style of package management.

An alternative that I have not used but looks promising is apropos.py :

, "apropos" Python. system.path , , docstrings .

:./apropos.py

- PyDoc apropos, , . apropos docstrings , .

+5

:

pydoc -k
0

All Articles