Python文檔生成工具pydoc使用介紹
在Python中有很多很好的工具來(lái)生成字符串文檔(docstring),比如說(shuō): epydoc、doxygen、sphinx,但始終覺得pydoc還是不錯(cuò)的工具,用法非常簡(jiǎn)單,功能也算不錯(cuò),本文主要介紹pydoc.
pydoc是Python自帶的模塊,主要用于從python模塊中自動(dòng)生成文檔,這些文檔可以基于文本呈現(xiàn)的、也可以生成WEB 頁(yè)面的,還可以在服務(wù)器上以瀏覽器的方式呈現(xiàn)!
【用法】
Windows下:
D:\>python -m pydoc <modulename> # 比如說(shuō): python -m pydoc math
-m參數(shù):Python以腳本的方法運(yùn)行模塊
Linux/Unix下:
$ pydoc <modulename> # 比如說(shuō): 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.
【參數(shù) -p】在本地機(jī)器上,按照給定的端口啟動(dòng)HTTP,
D:\>python -m pydoc -p 1234 #比如說(shuō): 端口為1234
pydoc server ready at http://localhost:1234/
pydoc server stopped
在IE中輸入:http://localhost:1234/,效果如圖:
【參數(shù) -k】在所有可用的模塊中按關(guān)鍵字搜索
$ 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
【參數(shù) -w】將指定模塊的文本字符串生成HTML格式
比如說(shuō),在Window下面,執(zhí)行下面命令:
D:\Learn\Python>python -m pydoc math -w math.html # math是模塊名,-w:寫
那么在D:\Learn\Python目錄下會(huì)生成math.html文件,顯示如下:
因?yàn)槭亲詭У哪K,所以右上角顯示(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 <x>
'''
return x * x
執(zhí)行命令:
D:\Learn\Python> python -m pydoc my_doc
執(zhí)行結(jié)果:
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 <x>
DATA
__authors__ = 'Alice & Fred'
__license__ = 'Copyright...'
__version__ = 'version 1.10'
VERSION
version 1.10
執(zhí)行命令:
d:\Learn\Python>python -m pydoc -w my_doc my_doc.html
wrote my_doc.html
no Python documentation found for 'my_doc.html'
執(zhí)行結(jié)果:
相關(guān)文章
ubuntu安裝jupyter并設(shè)置遠(yuǎn)程訪問(wèn)的實(shí)現(xiàn)
Jupyter?Notebook是Ipython的升級(jí)版,而Ipython可以說(shuō)是一個(gè)加強(qiáng)版的交互式Shell,本文主要介紹了ubuntu安裝jupyter并設(shè)置遠(yuǎn)程訪問(wèn)的實(shí)現(xiàn),感興趣的可以了解一下2022-03-03膠水語(yǔ)言Python與C/C++的相互調(diào)用的實(shí)現(xiàn)
這篇文章主要介紹了膠水語(yǔ)言Python與C/C++的相互調(diào)用的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-05-05python 創(chuàng)建一維的0向量實(shí)例
今天小編就為大家分享一篇python 創(chuàng)建一維的0向量實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-12-12在IPython中進(jìn)行Python程序執(zhí)行時(shí)間的測(cè)量方法
今天小編就為大家分享一篇在IPython中進(jìn)行Python程序執(zhí)行時(shí)間的測(cè)量方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-11-11Python容器類型轉(zhuǎn)換的3種方法實(shí)例
使用Python我們可以輕松地將數(shù)據(jù)轉(zhuǎn)換成不同的類型,下面這篇文章主要給大家介紹了關(guān)于Python容器類型轉(zhuǎn)換的3種方法,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-05-05Python?數(shù)據(jù)篩選功能實(shí)現(xiàn)
這篇文章主要介紹了Python?數(shù)據(jù)篩選,無(wú)論是在數(shù)據(jù)分析還是數(shù)據(jù)挖掘的時(shí)候,數(shù)據(jù)篩選總會(huì)涉及到,這里我總結(jié)了一下python中列表,字典,數(shù)據(jù)框中一些常用的數(shù)據(jù)篩選的方法,需要的朋友可以參考下2023-04-04Python3爬蟲學(xué)習(xí)之將爬取的信息保存到本地的方法詳解
這篇文章主要介紹了Python3爬蟲學(xué)習(xí)之將爬取的信息保存到本地的方法,結(jié)合實(shí)例形式詳細(xì)分析了Python3信息爬取、文件讀寫、圖片存儲(chǔ)等相關(guān)操作技巧,需要的朋友可以參考下2018-12-12Python 爬蟲批量爬取網(wǎng)頁(yè)圖片保存到本地的實(shí)現(xiàn)代碼
這篇文章主要介紹了Python 爬蟲批量爬取網(wǎng)頁(yè)圖片保存到本地,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-12-12基于Python寫個(gè)"點(diǎn)球大戰(zhàn)"小游戲
這篇文章主要為大家詳細(xì)介紹了如何利用Python寫個(gè)簡(jiǎn)單的"點(diǎn)球大戰(zhàn)"小游戲,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2022-12-12