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