Python文档生成工具pydoc
来源:互联网 发布:js中target属性 编辑:程序博客网 时间:2024/05/01 02:08
在Python中有很多很好的工具来生成字符串文档(docstring),比如说: epydoc、doxygen、sphinx,但始终觉得pydoc还是不错的工具,用法非常简单,功能也算不错,本文主要介绍pydoc.
pydoc是Python自带的模块,主要用于从python模块中自动生成文档,这些文档可以基于文本呈现的、也可以生成WEB 页面的,还可以在服务器上以浏览器的方式呈现!
【用法】
Windows下:
D:\>python -m pydoc <modulename> # 比如说: python -m pydoc math
-m参数:Python以脚本的方法运行模块
$ pydoc <modulename> # 比如说: pydoc【帮助】
$ pydoc -hpydoc - the Python documentation toolpydoc <name> ... Show text documentation on something. <name> <span id="8_nwp" style="padding: 0px; width: auto; height: auto; float: none;"><a target=_blank id="8_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=47&ch=0&di=128&fv=19&is_app=0&jk=6b0eca499105b816&k=may&k0=may&kdi0=0&luki=2&n=10&p=baidu&q=65035100_cpr&rb=0&rs=1&seller_id=1&sid=16b8059149ca0e6b&ssp2=1&stid=0&t=tpclicked3_hc&td=1836545&tu=u1836545&u=http%3A%2F%2Fwww%2Ebubuko%2Ecom%2Finfodetail%2D650630%2Ehtml&urlid=0" target="_blank" mpid="8" style="padding: 0px; color: rgb(51, 51, 51); text-decoration: none;"><span style="padding: 0px; color: rgb(0, 0, 255); width: auto; height: auto;">may</span></a></span> be the name of a Python keyword, <span id="9_nwp" style="padding: 0px; width: auto; height: auto; float: none;"><a target=_blank id="9_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=47&ch=0&di=128&fv=19&is_app=0&jk=6b0eca499105b816&k=topic&k0=topic&kdi0=0&luki=1&n=10&p=baidu&q=65035100_cpr&rb=0&rs=1&seller_id=1&sid=16b8059149ca0e6b&ssp2=1&stid=0&t=tpclicked3_hc&td=1836545&tu=u1836545&u=http%3A%2F%2Fwww%2Ebubuko%2Ecom%2Finfodetail%2D650630%2Ehtml&urlid=0" target="_blank" mpid="9" style="padding: 0px; color: rgb(51, 51, 51); text-decoration: none;"><span style="padding: 0px; color: rgb(0, 0, 255); width: auto; height: auto;">topic</span></a></span>, 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 <span id="10_nwp" style="padding: 0px; width: auto; height: auto; float: none;"><a target=_blank id="10_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=47&ch=0&di=128&fv=19&is_app=0&jk=6b0eca499105b816&k=server&k0=server&kdi0=0&luki=5&n=10&p=baidu&q=65035100_cpr&rb=0&rs=1&seller_id=1&sid=16b8059149ca0e6b&ssp2=1&stid=0&t=tpclicked3_hc&td=1836545&tu=u1836545&u=http%3A%2F%2Fwww%2Ebubuko%2Ecom%2Finfodetail%2D650630%2Ehtml&urlid=0" target="_blank" mpid="10" style="padding: 0px; color: rgb(51, 51, 51); text-decoration: none;"><span style="padding: 0px; color: rgb(0, 0, 255); width: auto; height: auto;">server</span></a></span> on the given port on the local <span id="11_nwp" style="padding: 0px; width: auto; height: auto; float: none;"><a target=_blank id="11_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=47&ch=0&di=128&fv=19&is_app=0&jk=6b0eca499105b816&k=machine&k0=machine&kdi0=0&luki=7&n=10&p=baidu&q=65035100_cpr&rb=0&rs=1&seller_id=1&sid=16b8059149ca0e6b&ssp2=1&stid=0&t=tpclicked3_hc&td=1836545&tu=u1836545&u=http%3A%2F%2Fwww%2Ebubuko%2Ecom%2Finfodetail%2D650630%2Ehtml&urlid=0" target="_blank" mpid="11" style="padding: 0px; color: rgb(51, 51, 51); text-decoration: none;"><span style="padding: 0px; color: rgb(0, 0, 255); width: auto; height: auto;">machine</span></a></span>.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 <span id="6_nwp" style="padding: 0px; width: auto; height: auto; float: none;"><a target=_blank id="6_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=47&ch=0&di=128&fv=19&is_app=0&jk=6b0eca499105b816&k=xml&k0=xml&kdi0=0&luki=9&n=10&p=baidu&q=65035100_cpr&rb=0&rs=1&seller_id=1&sid=16b8059149ca0e6b&ssp2=1&stid=0&t=tpclicked3_hc&td=1836545&tu=u1836545&u=http%3A%2F%2Fwww%2Ebubuko%2Ecom%2Finfodetail%2D650630%2Ehtml&urlid=0" target="_blank" mpid="6" style="padding: 0px; color: rgb(51, 51, 51); text-decoration: none;"><span style="padding: 0px; color: rgb(0, 0, 255); width: auto; height: auto;">xml</span></a></span>.saxxml.sax (package) - Simple API for XML (SAX) implementation for Python.xml.sax._exceptions - Different kinds 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.<span id="7_nwp" style="padding: 0px; width: auto; height: auto; float: none;"><a target=_blank id="7_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=47&ch=0&di=128&fv=19&is_app=0&jk=6b0eca499105b816&k=xml&k0=xml&kdi0=0&luki=9&n=10&p=baidu&q=65035100_cpr&rb=0&rs=1&seller_id=1&sid=16b8059149ca0e6b&ssp2=1&stid=0&t=tpclicked3_hc&td=1836545&tu=u1836545&u=http%3A%2F%2Fwww%2Ebubuko%2Ecom%2Finfodetail%2D650630%2Ehtml&urlid=0" target="_blank" mpid="7" style="padding: 0px; color: rgb(51, 51, 51); text-decoration: none;"><span style="padding: 0px; color: rgb(0, 0, 255); width: auto; height: auto;">xml</span></a></span>reader - An XML Reader is the SAX 2 name for an XML parser. XML Parsers【参数 -w】将指定模块的文本字符串生成HTML格式
比如说,在Window下面,执行下面命令:
D:\Learn\Python>python -m pydoc math -w math.html # math是模块名,-w:写那么在D:\Learn\Python目录下会生成math.html文件,显示如下:
因为是自带的模块,所以右上角显示(built-in)字样
【例子】自写的模块my_doc.py
'''Showoff features of Pydoc moduleThis 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 <span id="5_nwp" style="padding: 0px; width: auto; height: auto; float: none;"><a target=_blank id="5_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=47&ch=0&di=128&fv=19&is_app=0&jk=6b0eca499105b816&k=only&k0=only&kdi0=0&luki=6&n=10&p=baidu&q=65035100_cpr&rb=0&rs=1&seller_id=1&sid=16b8059149ca0e6b&ssp2=1&stid=0&t=tpclicked3_hc&td=1836545&tu=u1836545&u=http%3A%2F%2Fwww%2Ebubuko%2Ecom%2Finfodetail%2D650630%2Ehtml&urlid=0" target="_blank" mpid="5" style="padding: 0px; color: rgb(51, 51, 51); text-decoration: none;"><span style="padding: 0px; color: rgb(0, 0, 255); width: auto; height: auto;">only</span></a></span> Keyword arguments: spam - a processed meat product eggs - a fine breakfast for lumberjacks ''' self.spam = spam self.eggs = eggsdef square(x): ''' Square of the param <x> ''' return x * x执行命令:
D:\Learn\Python> <span id="4_nwp" style="padding: 0px; width: auto; height: auto; float: none;"><a target=_blank id="4_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=47&ch=0&di=128&fv=19&is_app=0&jk=6b0eca499105b816&k=python&k0=python&kdi0=0&luki=10&n=10&p=baidu&q=65035100_cpr&rb=0&rs=1&seller_id=1&sid=16b8059149ca0e6b&ssp2=1&stid=0&t=tpclicked3_hc&td=1836545&tu=u1836545&u=http%3A%2F%2Fwww%2Ebubuko%2Ecom%2Finfodetail%2D650630%2Ehtml&urlid=0" target="_blank" mpid="4" style="padding: 0px; color: rgb(51, 51, 51); text-decoration: none;"><span style="padding: 0px; color: rgb(0, 0, 255); width: auto; height: auto;">python</span></a></span> -m pydoc my_doc执行结果:
Help on module my_doc:NAME my_docFILE d:\learn\<span id="2_nwp" style="padding: 0px; width: auto; height: auto; float: none;"><a target=_blank id="2_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=47&ch=0&di=128&fv=19&is_app=0&jk=6b0eca499105b816&k=python&k0=python&kdi0=0&luki=10&n=10&p=baidu&q=65035100_cpr&rb=0&rs=1&seller_id=1&sid=16b8059149ca0e6b&ssp2=1&stid=0&t=tpclicked3_hc&td=1836545&tu=u1836545&u=http%3A%2F%2Fwww%2Ebubuko%2Ecom%2Finfodetail%2D650630%2Ehtml&urlid=0" target="_blank" mpid="2" style="padding: 0px; color: rgb(51, 51, 51); text-decoration: none;"><span style="padding: 0px; color: rgb(0, 0, 255); width: auto; height: auto;">python</span></a></span>\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 <span id="3_nwp" style="padding: 0px; width: auto; height: auto; float: none;"><a target=_blank id="3_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=47&ch=0&di=128&fv=19&is_app=0&jk=6b0eca499105b816&k=only&k0=only&kdi0=0&luki=6&n=10&p=baidu&q=65035100_cpr&rb=0&rs=1&seller_id=1&sid=16b8059149ca0e6b&ssp2=1&stid=0&t=tpclicked3_hc&td=1836545&tu=u1836545&u=http%3A%2F%2Fwww%2Ebubuko%2Ecom%2Finfodetail%2D650630%2Ehtml&urlid=0" target="_blank" mpid="3" style="padding: 0px; color: rgb(51, 51, 51); text-decoration: none;"><span style="padding: 0px; color: rgb(0, 0, 255); width: auto; height: auto;">only</span></a></span> | 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执行命令:
d:\Learn\Python>python -m pydoc -w my_doc my_doc.htmlwrote my_doc.htmlno Python documentation found for 'my_doc.html'执行结果:
官方文档:
https://docs.python.org/2/library/pydoc.html
0 0
- Python文档生成工具pydoc
- Python文档生成工具pydoc
- Python文档生成工具pydoc
- Python文档生成工具pydoc使用介绍
- Python文档生成工具pydoc使用介绍
- Python文档生成工具pydoc使用介绍
- python文档生成工具pydoc在网页上查看的方法
- 使用Pydoc生成文档
- python查看帮助文档的命令--pydoc
- Python pydoc模块
- python获取pydoc
- python查看pydoc
- Python: pydoc 和 distutils 模块
- python的开发手册 pydoc
- Python定制自己的实体类说明文档生成工具
- 文档生成工具-NaturalDocs
- JAVASCRIPT 文档生成工具
- 帮助文档生成工具
- leetcode笔记:Reorder List
- 离散化 + 线段树(树状数组) + 线扫描法
- 阿里面试经历总结
- Longest Valid Parentheses
- hdu5491(2015合肥网络赛H题)
- Python文档生成工具pydoc
- Fragment
- Java垃圾回收工作原理
- Android应用优化(7)数据库操作
- runloop 详解
- 快速排序算法
- Nexus私服搭建与应用
- 简单工厂模式
- 上传进度回退的几种情况