Python Document Generation tool Pydoc

Source: Internet
Author: User
Tags xml parser xml reader

In Python there are a lot of good tools to generate string documents (docstring), such as: Epydoc, Doxygen, Sphinx, but always think Pydoc is a good tool, the usage is very simple, the function is good, this article mainly introduces Pydoc.

Pydoc is a python-brought module that is used to automatically generate documents from Python modules that can be rendered on text-based, web pages, and in a browser on the server!

" usage "

Under Windows:

D:\>python-m Pydoc <modulename>   # For example, python-m Pydoc Math  

-m parameter: Python runs the module in a scripted way


Linux/unix under:

$ Pydoc <modulename>               
" help "
$ pydoc-hpydoc-the Python documentation Toolpydoc <name> ...  Show text documentation on something. <name> May is the name of a Python keyword, topic, function, module, or package, or a dotted reference to a CL  The or function within a module or module in a package. If <name> contains a '/', it is used as the path to a Python source file to document. If name is ' keywords ', ' topics ', or ' modules ', a listing of these things is Displayed.pydoc-k <keyword> Searc h for a keyword in the synopsis lines of all available modules.pydoc-p <port> Start an HTTP server on the given    Port on the local machine.pydoc-w <name> ...  The Write out of the HTML documentation for a module to a file in the current directory. If <name> contains a '/', it is treated as a filename; If it names a directory, documentation is written for all the contents.
the parameter-P "On the local machine, start HTTP on the given port,

d:\>python-m pydoc-p 1234 #比如说: port is 1234

Pydoc Server Ready at http://localhost:1234/

Pydoc Server stopped

Input in IE:http://localhost:1234/, Effect:


the parameter-K "Search by keyword in all available modules

$ pydoc-k Xml.saxxml.sax (Package)-Simple API for XML (sax) implementation for Python.xml.sax._exceptions-different K Inds of SAX Exceptionsxml.sax.expatreader-sax driver for the Pyexpat C module.  This driver Works Withxml.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 Thexml.sax.xmlreader-an XML Reader is the SAX 2 n Ame for the XML parser. XML parsers
the parameter-w "Generates HTML formatting for the specified module's text string

For example, under Window, execute the following command:

D:\learn\python>python-m Pydoc math-w math.html  # Math is the module name,-W: Write
then the math.html file will be generated under the D:\Learn\Python directory, as shown below:


Because it comes with the module, the upper right corner shows (built-in) the word

" Example "self-written module my_doc.py

"' Showoff features of Pydoc Modulethis is easy module to demonstrate docstrings ' ' __authors__  = ' Alice & Fred ' __v ersion__  = ' 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 = Spa M        Self.eggs = Eggsdef Square (x):    ' square of the    param <x>    '    return x * x
Execute command:
d:\learn\python> python-m Pydoc My_doc
Execution Result:
Help on module My_doc:name    my_docfile    D:\learn\python\my_doc.pyDESCRIPTION    showoff features of Pydoc Module This is easy    module to demonstrate docstringsclasses    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 lumberjacksfunctions    Square (x)        square of the param <x>data    __authors__ = ' Alice & Fred '    __license__ = ' Copyright ... '    __version__ = ' version 1.10 ' version    version 1.10
Execute command:
D:\learn\python>python-m pydoc-w my_doc my_doc.htmlwrote my_doc.htmlno Python documentation found for ' my_doc.html '
Execution Result:



Official documents:

Https://docs.python.org/2/library/pydoc.html


Python Document Generation tool Pydoc

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.