Python Document Generation tool Pydoc usage Introduction

Source: Internet
Author: User
Tags documentation xml parser xml reader in python

This article mainly introduces the Python document generation tool Pydoc use introduction, this article explained the basic usage, obtains the help the method, produces the document effect diagram and so on content, needs the friend to be possible to refer to under

There are a lot of good tools in Python to generate string documents (docstring), such as: Epydoc, Doxygen, sphinx, but always feel that the pydoc is a good tool, the usage is very simple, the function is also good, this article mainly introduces Pydoc.

Pydoc is a Python self-contained module that is used to automatically generate documents from Python modules that can be rendered based on text, can also generate Web pages, and can be rendered on the server in a browser format!

Usage

Under Windows:

The code is as follows:

D:>python-m Pydoc # For example, python-m pydoc math

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

Linux/unix under:

The code is as follows:

$ pydoc # For example, Pydoc

Help

The code is as follows:

$ pydoc-h

Pydoc-the Python Documentation Tool

Pydoc ...

Show text documentation on something. May is the name of a

Python keyword, topic, function, module, or package, or a dotted

Reference to a class or function within a module or module in a

Package. If 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 are displayed.

Pydoc-k

Search for a keyword in the synopsis lines of all available modules.

Pydoc-p

Start a HTTP server on the given port on the local machine.

Pydoc-w ...

Write out of 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 to all the contents.

Parameter-P starts HTTP on the local machine, with the given port,

The code is as follows:

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

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

Pydoc Server stopped

In IE input: http://localhost:1234/, the effect as shown:

Parameter-K searches all available modules by keyword

The code is as follows:

$ pydoc-k Xml.sax

Xml.sax (Package)-Simple APIs 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 with

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 the

Xml.sax.xmlreader-an XML Reader is the SAX 2 name of XML parser. XML parsers

Parameter-W generates HTML formatting for the text string of the specified module

For example, under Window, execute the following command:

The code is as follows:

D:learnpython>python-m pydoc math-w math.html # Math is the module name, W: Write

Then the math.html file is generated under the D:learnpython directory, which appears as follows:

Because it is a self-contained module, the upper-right corner shows (built-in) the words

"Example" self-written module my_doc.py

The code is as follows:

'''''

Showoff Features of Pydoc module

This are 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

To execute a command:

The code is as follows:

d:learnpython> python-m Pydoc My_doc

Execution results:

The code is as follows:

Help on module My_doc:

NAME

My_doc

FILE

d:learnpythonmy_doc.py

DESCRIPTION

Showoff Features of Pydoc module

This are 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

To execute a command:

The code is as follows:

D:learnpython>python-m pydoc-w My_doc my_doc.html

Wrote my_doc.html

No Python documentation found for ' my_doc.html '

Execution results:

Related Article

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.