在Python中有很多很好的工具来生成字符串文档(docstring),比如说: epydoc、doxygen、sphinx,但始终觉得pydoc还是不错的工具,用法非常简单,功能也算不错,本文主要介绍pydoc.
pydoc是Python自带的模块,主要用于从python模块中自动生成文档,这些文档可以基于文本呈现的、也可以生成WEB 页面的,还可以在服务器上以浏览器的方式呈现!
【用法】
Windows下:
 代码如下:
D:/>python -m pydoc <modulename>   # 比如说: python -m pydoc math    
-m参数:Python以脚本的方法运行模块
Linux/Unix下:
 代码如下:
$ pydoc <modulename>               # 比如说: pydoc   
【帮助】
 代码如下:
$ pydoc -h  
pydoc - the Python documentation tool  
  
  
pydoc <name> ...  
    Show text documentation on something.  <name> may be 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 <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>  
    Search 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> ...  
    Write out 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.  
【参数 -p】在本地机器上,按照给定的端口启动HTTP,
 代码如下:
D:/>python -m pydoc -p 1234 #比如说: 端口为1234
pydoc server ready at http://localhost:1234/
pydoc server stopped
在IE中输入:http://localhost:1234/,效果如图:

【参数 -k】在所有可用的模块中按关键字搜索
 代码如下:
$ 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 with              
新闻热点
疑难解答