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

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

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

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

Windows下:

復制代碼 代碼如下:

D:\>python -m pydoc <modulename>   # 比如說: python -m pydoc math   
-m參數(shù):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. 

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

復制代碼 代碼如下:

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

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

【參數(shù) -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 

【參數(shù) -w】將指定模塊的文本字符串生成HTML格式
比如說,在Window下面,執(zhí)行下面命令:
復制代碼 代碼如下:

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 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í)行結果:
復制代碼 代碼如下:

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í)行結果:


您可能感興趣的文章:

相關文章

  • python3使用sqlite3構建本地持久化緩存的過程

    python3使用sqlite3構建本地持久化緩存的過程

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

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

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

    利用Python實現(xiàn)網(wǎng)絡運維自動化的實戰(zhàn)案例

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

    Python 字符串換行的多種方式

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

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

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

    python 繪制國旗的示例

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

    一篇文章帶你了解python標準庫--sys模塊

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

    利用Python解決構造回文字符串問題的方法

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

    基于Python編寫一個點名器的示例代碼

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

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

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

最新評論

乐业县| 南江县| 双桥区| 永吉县| 秭归县| 泰和县| 登封市| 谷城县| 上栗县| 讷河市| 顺义区| 定西市| 永昌县| 苗栗县| 罗平县| 唐河县| 连云港市| 喜德县| 崇义县| 扶余县| 轮台县| 蕉岭县| 阳信县| 响水县| 宜兰县| 衡阳市| 本溪市| 芦山县| 双城市| 永登县| 西乌珠穆沁旗| 拉孜县| 通河县| 苍梧县| 介休市| 扎囊县| 江源县| 博兴县| 留坝县| 东港市| 东山县|