python-mpydoc#比" />

亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

Python文檔生成工具pydoc使用介紹

系統 2510 0

在Python中有很多很好的工具來生成字符串文檔(docstring),比如說: epydoc、doxygen、sphinx,但始終覺得pydoc還是不錯的工具,用法非常簡單,功能也算不錯,本文主要介紹pydoc.
pydoc是Python自帶的模塊,主要用于從python模塊中自動生成文檔,這些文檔可以基于文本呈現的、也可以生成WEB 頁面的,還可以在服務器上以瀏覽器的方式呈現!
【用法】

Windows下:

復制代碼 代碼如下:

D:\>python -m pydoc ?? # 比如說: python -m pydoc math???
-m參數:Python以腳本的方法運行模塊

Linux/Unix下:

復制代碼 代碼如下:

$ pydoc ?????????????? # 比如說: pydoc??

【幫助】

復制代碼 代碼如下:

$ pydoc -h?
pydoc - the Python documentation tool?
?
?
pydoc ...?
??? Show text documentation on something.? 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 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 ?
??? 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.?

【參數 -p】在本地機器上,按照給定的端口啟動HTTP,

復制代碼 代碼如下:

D:\>python -m pydoc -p 1234 #比如說: 端口為1234
pydoc server ready at http://localhost:1234/
pydoc server stopped

在IE中輸入:http://localhost:1234/,效果如圖:

Python文檔生成工具pydoc使用介紹_第1張圖片

【參數 -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?
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 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文件,顯示如下:

Python文檔生成工具pydoc使用介紹_第2張圖片

因為是自帶的模塊,所以右上角顯示(built-in)字樣
【例子】自寫的模塊my_doc.py

復制代碼 代碼如下:

'''''
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?

執行命令:

復制代碼 代碼如下:

D:\Learn\Python> python -m pydoc my_doc

執行結果:
復制代碼 代碼如下:

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?

執行命令:

復制代碼 代碼如下:

d:\Learn\Python>python -m pydoc -w my_doc my_doc.html?
wrote my_doc.html?
no Python documentation found for 'my_doc.html'?

執行結果:

Python文檔生成工具pydoc使用介紹_第3張圖片


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 亚洲欧美不卡中文字幕 | 国产福利一区二区精品视频 | 国产成人a在一区线观看高清 | 一级毛片视频在线 | 91成人午夜精品福利院在线观看 | 国产亚洲影院 | 久久精品免视看国产陈冠希 | 五月婷婷在线视频观看 | 国产精品一区伦免视频播放 | 四虎影院视频在线观看 | 日本aⅴ网站 | 亚洲国产激情 | 国产精品欧美亚洲韩国日本不卡 | 亚洲精品乱码中文字幕无线 | 狠狠色噜噜综合社区 | 69精品在线观看 | 天天操天天摸天天舔 | 国产成人乱码一区二区三区 | 亚洲精品高清在线一区二区三区 | 自拍亚洲午夜伦li片影院 | 亚洲精品一区亚洲精品 | 四虎永久在线精品免费影视 | 精品国产线拍大陆久久尤物 | 奇米视频888 | 国产真实强j视频在线观看 国产真实偷乱视频在线观看 | 国产精品免费久久久久影院 | 九热爱视频精品视频 | 国产免费看 | 色女人久久 | 色成年激情久久综合 | 国产成人精品免费视频大全五级 | 2046影院视频大全在线观看 | 亚洲99在线的 | 九九视频在线观看视频 | a久久| 久久视屏这里只有精品6国产 | 亚洲精品第一区二区三区 | 国产精品日本一区二区在线看 | 香蕉网伊在线中文慕大全 | 欧美三级一区二区三区 | 99久久香蕉国产线看观香 |