Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1 | :mod:`pydoc` --- Documentation generator and online help system |
| 2 | =============================================================== |
| 3 | |
| 4 | .. module:: pydoc |
| 5 | :synopsis: Documentation generator and online help system. |
| 6 | .. moduleauthor:: Ka-Ping Yee <ping@lfw.org> |
| 7 | .. sectionauthor:: Ka-Ping Yee <ping@lfw.org> |
| 8 | |
| 9 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 10 | .. index:: |
| 11 | single: documentation; generation |
| 12 | single: documentation; online |
| 13 | single: help; online |
| 14 | |
| 15 | The :mod:`pydoc` module automatically generates documentation from Python |
| 16 | modules. The documentation can be presented as pages of text on the console, |
| 17 | served to a Web browser, or saved to HTML files. |
| 18 | |
| 19 | The built-in function :func:`help` invokes the online help system in the |
| 20 | interactive interpreter, which uses :mod:`pydoc` to generate its documentation |
| 21 | as text on the console. The same text documentation can also be viewed from |
| 22 | outside the Python interpreter by running :program:`pydoc` as a script at the |
| 23 | operating system's command prompt. For example, running :: |
| 24 | |
| 25 | pydoc sys |
| 26 | |
| 27 | at a shell prompt will display documentation on the :mod:`sys` module, in a |
| 28 | style similar to the manual pages shown by the Unix :program:`man` command. The |
| 29 | argument to :program:`pydoc` can be the name of a function, module, or package, |
| 30 | or a dotted reference to a class, method, or function within a module or module |
| 31 | in a package. If the argument to :program:`pydoc` looks like a path (that is, |
| 32 | it contains the path separator for your operating system, such as a slash in |
| 33 | Unix), and refers to an existing Python source file, then documentation is |
| 34 | produced for that file. |
| 35 | |
Benjamin Peterson | da10d3b | 2009-01-01 00:23:30 +0000 | [diff] [blame] | 36 | .. note:: |
| 37 | |
| 38 | In order to find objects and their documentation, :mod:`pydoc` imports the |
| 39 | module(s) to be documented. Therefore, any code on module level will be |
| 40 | executed on that occasion. Use an ``if __name__ == '__main__':`` guard to |
| 41 | only execute code when a file is invoked as a script and not just imported. |
| 42 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 43 | Specifying a :option:`-w` flag before the argument will cause HTML documentation |
| 44 | to be written out to a file in the current directory, instead of displaying text |
| 45 | on the console. |
| 46 | |
| 47 | Specifying a :option:`-k` flag before the argument will search the synopsis |
| 48 | lines of all available modules for the keyword given as the argument, again in a |
| 49 | manner similar to the Unix :program:`man` command. The synopsis line of a |
| 50 | module is the first line of its documentation string. |
| 51 | |
| 52 | You can also use :program:`pydoc` to start an HTTP server on the local machine |
| 53 | that will serve documentation to visiting Web browsers. :program:`pydoc` |
| 54 | :option:`-p 1234` will start a HTTP server on port 1234, allowing you to browse |
| 55 | the documentation at ``http://localhost:1234/`` in your preferred Web browser. |
| 56 | :program:`pydoc` :option:`-g` will start the server and additionally bring up a |
Ezio Melotti | 1a263ad | 2010-03-14 09:51:37 +0000 | [diff] [blame] | 57 | small :mod:`tkinter`\ -based graphical interface to help you search for |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 58 | documentation pages. |
| 59 | |
| 60 | When :program:`pydoc` generates documentation, it uses the current environment |
| 61 | and path to locate modules. Thus, invoking :program:`pydoc` :option:`spam` |
| 62 | documents precisely the version of the module you would get if you started the |
| 63 | Python interpreter and typed ``import spam``. |
| 64 | |
| 65 | Module docs for core modules are assumed to reside in |
Georg Brandl | 86def6c | 2008-01-21 20:36:10 +0000 | [diff] [blame] | 66 | http://docs.python.org/library/. This can be overridden by setting the |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 67 | :envvar:`PYTHONDOCS` environment variable to a different URL or to a local |
| 68 | directory containing the Library Reference Manual pages. |
| 69 | |