Python document generation tool pydoc usage

Source: Internet
Author: User
Tags xml parser xml reader
This article mainly introduces the Python document generation tool pydoc. This article describes the basic usage, how to get help, and the generated documents, you can refer to many good tools in Python to generate string documents (docstring), such as epydoc, doxygen, and sphgen. However, pydoc is always a good tool, this document 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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.