最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2015年06月02日 17:04:53   投稿:junjie  
這篇文章主要介紹了Python文檔生成工具pydoc使用介紹,本文講解了基本用法、獲取幫助的方法、生成的文檔效果圖等內(nèi)容,需要的朋友可以參考下

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

Windows下:

復(fù)制代碼 代碼如下:

D:\>python -m pydoc <modulename>   # 比如說: python -m pydoc math   
-m參數(shù):Python以腳本的方法運(yùn)行模塊

Linux/Unix下:

復(fù)制代碼 代碼如下:

$ pydoc <modulename>               # 比如說: pydoc  

【幫助】

復(fù)制代碼 代碼如下:

$ 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,

復(fù)制代碼 代碼如下:

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

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

【參數(shù) -k】在所有可用的模塊中按關(guān)鍵字搜索

復(fù)制代碼 代碼如下:

$ 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格式
比如說,在Window下面,執(zhí)行下面命令:
復(fù)制代碼 代碼如下:

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

復(fù)制代碼 代碼如下:

'''''
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í)行命令:

復(fù)制代碼 代碼如下:

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

執(zhí)行結(jié)果:
復(fù)制代碼 代碼如下:

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í)行命令:

復(fù)制代碼 代碼如下:

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)文章

  • python3使用sqlite3構(gòu)建本地持久化緩存的過程

    python3使用sqlite3構(gòu)建本地持久化緩存的過程

    日常python開發(fā)中會(huì)遇到數(shù)據(jù)持久化的問題,今天記錄下如何使用sqlite3進(jìn)行數(shù)據(jù)持久化,并提供示例代碼及數(shù)據(jù)查看工具,需要的朋友可以參考下
    2023-11-11
  • 簡(jiǎn)單介紹Python中的decode()方法的使用

    簡(jiǎn)單介紹Python中的decode()方法的使用

    這篇文章主要介紹了簡(jiǎn)單介紹Python中的decode()方法的使用,是Python入門學(xué)習(xí)當(dāng)中必須掌握的基礎(chǔ)知識(shí),需要的朋友可以參考下
    2015-05-05
  • 利用Python實(shí)現(xiàn)網(wǎng)絡(luò)運(yùn)維自動(dòng)化的實(shí)戰(zhàn)案例

    利用Python實(shí)現(xiàn)網(wǎng)絡(luò)運(yùn)維自動(dòng)化的實(shí)戰(zhàn)案例

    Python作為一種簡(jiǎn)潔而強(qiáng)大的編程語言,已經(jīng)成為網(wǎng)絡(luò)運(yùn)維自動(dòng)化的熱門選擇,本文將介紹如何利用Python實(shí)現(xiàn)網(wǎng)絡(luò)設(shè)備配置管理、監(jiān)控和故障排除等自動(dòng)化任務(wù),并提供代碼示例,需要的朋友可以參考下
    2024-03-03
  • Python 字符串換行的多種方式

    Python 字符串換行的多種方式

    本文通過四種方法給大家介紹了Python 字符串換行的方式,在文中最下面通過代碼給大家介紹了python代碼過長(zhǎng)的換行方法,需要的朋友可以參考下
    2018-09-09
  • python常用的各種排序算法原理與實(shí)現(xiàn)方法小結(jié)

    python常用的各種排序算法原理與實(shí)現(xiàn)方法小結(jié)

    這篇文章主要介紹了python常用的各種排序算法原理與實(shí)現(xiàn)方法,結(jié)合實(shí)例形式總結(jié)分析了冒泡排序、插入排序、選擇排序、快速排序等排序算法的相關(guān)原理與實(shí)現(xiàn)方法,需要的朋友可以參考下
    2023-04-04
  • python 繪制國(guó)旗的示例

    python 繪制國(guó)旗的示例

    這篇文章主要介紹了python 繪制國(guó)旗的示例,幫助大家利用python繪制,處理圖像,感興趣的朋友可以了解下
    2020-09-09
  • 一篇文章帶你了解python標(biāo)準(zhǔn)庫--sys模塊

    一篇文章帶你了解python標(biāo)準(zhǔn)庫--sys模塊

    這篇文章主要介紹了Python標(biāo)準(zhǔn)庫之Sys模塊使用詳解,本文講解了使用sys模塊獲得腳本的參數(shù)、處理模塊、使用sys模塊操作模塊搜索路徑、使用sys模塊查找內(nèi)建模塊、使用sys模塊查找已導(dǎo)入的模塊等使用案例,需要的朋友可以參考下
    2021-08-08
  • 利用Python解決構(gòu)造回文字符串問題的方法

    利用Python解決構(gòu)造回文字符串問題的方法

    回文字符串是指正讀和反讀都相同的字符串,例如"aba"或"abba",構(gòu)造回文字符串問題通常涉及從給定字符串中刪除某些字符,以形成最長(zhǎng)的回文子序列,或者計(jì)算形成回文所需的最小刪除次數(shù),本文將詳細(xì)介紹如何使用Python和動(dòng)態(tài)規(guī)劃算法來解決構(gòu)造回文字符串問題
    2025-04-04
  • 基于Python編寫一個(gè)點(diǎn)名器的示例代碼

    基于Python編寫一個(gè)點(diǎn)名器的示例代碼

    想起小學(xué)的時(shí)候老師想點(diǎn)名找小伙伴回答問題的時(shí)候,老師竟斥巨資買了個(gè)點(diǎn)名器。今日無聊便敲了敲小時(shí)候老師斥巨資買的點(diǎn)名器,希望對(duì)大家有幫助
    2022-07-07
  • 在 Python 中接管鍵盤中斷信號(hào)的實(shí)現(xiàn)方法

    在 Python 中接管鍵盤中斷信號(hào)的實(shí)現(xiàn)方法

    要使用信號(hào),我們需用導(dǎo)入 Python 的signal庫。然后自定義一個(gè)信號(hào)回調(diào)函數(shù),當(dāng) Python 收到某個(gè)信號(hào)時(shí),調(diào)用這個(gè)函數(shù)。 ,下面通過實(shí)例代碼給大家介紹在 Python 中接管鍵盤中斷信號(hào),需要的朋友可以參考下
    2020-02-02

最新評(píng)論

巍山| 新晃| 同仁县| 织金县| 岳池县| 鄂伦春自治旗| 永兴县| 津市市| 梁山县| 广宗县| 遵义市| 克山县| 丰顺县| 独山县| 高尔夫| 高邮市| 许昌市| 龙门县| 康定县| 靖远县| 霍州市| 开鲁县| 诸暨市| 洪雅县| 防城港市| 温宿县| 出国| 辽阳县| 奇台县| 广元市| 当涂县| 安吉县| 尚义县| 确山县| 阿拉善左旗| 天峨县| 建阳市| 呼和浩特市| 宁城县| 郧西县| 太白县|