Python document generation tool pydoc usage
This article describes how to use the Python document generation tool pydoc. This article describes basic usage, how to get help, and generated documents. For more information, see
There are many good tools in Python to generate string documents (docstring), such as epydoc, doxygen, and sphgen, but I always think pydoc is a good tool and its usage is very simple, this article mainly introduces pydoc.
Pydoc is a Python module that is used to automatically generate documents from the python module. These documents can be displayed based on text or WEB pages, it can also be displayed in a browser on the server!
[Usage]
Windows:
The Code is as follows:
D: \> python-m pydoc # For example: python-m pydoc math
-M parameter: Python runs the module as a script
In Linux/Unix:
The Code is as follows:
$ Pydoc # Example: pydoc
Help]
The Code is as follows:
$ Pydoc-h
Pydoc-the Python documentation tool
Pydoc ...
Show text documentation on something. May be the name of
Python keyword, topic, function, module, or package, or a dotted
Reference to a class or function within a module or module in
Package. If Contains A'/', it is used as the path to
Python source file to document. If name is 'keyword', 'topics ',
Or 'modules', a listing of these things is displayed.
Pydoc-k
Search for a keyword in the synopsis lines of all available modules.
Pydoc-p
Start an HTTP server on the given port on the local machine.
Pydoc-w ...
Write out the HTML documentation for a module to a file in the current
Directory. If Contains A'/', it is treated as a filename; if
It names a directory, documentation is written for all the contents.
[Parameter-p] Start HTTP Based on the specified port on the local machine,
The Code is as follows:
D: \> python-m pydoc-p 1234 # For example, port 1234
Pydoc server ready at http: // localhost: 1234/
Pydoc server stopped
In IE, enter: http: // localhost: 1234/. effect:
[Parameter-k] search by keyword in all available modules
The Code is as follows:
$ Pydoc-k xml. sax
Xml. sax (package)-Simple API for XML (SAX) implementation for Python.
Xml. sax. _ exceptions-Different kinds of SAX Exceptions
Xml. sax. expatreader-SAX driver for the pyexpat C module. This driver works
Xml. sax. handler-This module contains the core classes of version 2.0 of SAX for Python.
Xml. sax. saxutils-A library of useful helper classes to the SAX classes, for
Xml. sax. xmlreader-An XML Reader is the SAX 2 name for an XML parser. XML Parsers
[Parameter-w] generates the text string of the specified module in HTML format.
For example, in the Window, execute the following command:
The Code is as follows:
D: \ Learn \ Python> python-m pydoc math-w math.html # math is the module name,-w: Write
The math.html file will be generated in the D: \ Learn \ pythondirectory, as shown below:
Because it is a built-in module, the words (built-in) are displayed in the upper right corner.
[Example] self-Writing module my_doc.py
The Code is as follows:
'''''
Showoff features of Pydoc module
This is easy module to demonstrate docstrings
'''
_ Authors _ = 'Alice & Fred'
_ Version _ = 'version 1.10'
_ License _ = 'copyright ...'
Class MyClass:
'''''
Demonstrate Class Docstrings
'''
Def _ init _ (self, spam = 1, eggs = 2 ):
'''''
Set the default attributevalues only
Keyword arguments:
Spam-a processed meat product
Eggs-a fine breakfast for lumberjacks
'''
Self. spam = spam
Self. eggs = eggs
Def square (x ):
'''''
Square of the param
'''
Return x * x
Run the following command:
The Code is as follows:
D: \ Learn \ Python> python-m pydoc my_doc
Execution result:
The Code is as follows:
Help on module my_doc:
NAME
My_doc
FILE
D: \ learn \ python \ my_doc.py
DESCRIPTION
Showoff features of Pydoc module
This is easy module to demonstrate docstrings
CLASSES
MyClass
Class MyClass
| Demonstrate Class Docstrings
|
| Methods defined here:
|
| _ Init _ (self, spam = 1, eggs = 2)
| Set the default attributevalues only
| Keyword arguments:
| Spam-a processed meat product
| Eggs-a fine breakfast for lumberjacks
FUNCTIONS
Square (x)
Square of the param
DATA
_ Authors _ = 'Alice & Fred'
_ License _ = 'copyright ...'
_ Version _ = 'version 1.10'
VERSION
Version 1.10:
Run the following command:
The Code is as follows:
D: \ Learn \ Python> python-m pydoc-w my_doc my_doc.html
Wrote my_doc.html
No Python documentation found for 'my_doc.html'
Execution result: