在Python中有很多很好的工具來生成字符串文檔(docstring),比如說: epydoc、doxygen、sphinx,但始終覺得pydoc還是不錯的工具,用法非常簡單,功能也算不錯,本文主要介紹pydoc.
pydoc是Python自帶的模塊,主要用于從python模塊中自動生成文檔,這些文檔可以基于文本呈現的、也可以生成WEB 頁面的,還可以在服務器上以瀏覽器的方式呈現!
【用法】
Windows下:
代碼如下:
D:/>python -m pydoc <modulename> # 比如說: python -m pydoc math
-m參數: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.
【參數 -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 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
新聞熱點
疑難解答