• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > Python文档生成工具pydoc使用介绍

Python文档生成工具pydoc使用介绍

作者:junjie 字体:[增加 减小] 来源:互联网

junjie 通过本文主要向大家介绍了python pydoc,python3 pydoc,pydoc,pydoc命令,pydoc怎么用等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

在Python中有很多很好的工具来生成字符串文档(docstring),比如说: epydoc、doxygen、sphinx,但始终觉得pydoc还是不错的工具,用法非常简单,功能也算不错,本文主要介绍pydoc.
pydoc是Python自带的模块,主要用于从python模块中自动生成文档,这些文档可以基于文本呈现的、也可以生成WEB 页面的,还可以在服务器上以浏览器的方式呈现!
【用法】

Windows下:
D:\>python -m pydoc <modulename>   # 比如说: python -m pydoc math   
-m参数:Python以脚本的方法运行模块
</div>

Linux/Unix下:
$ pydoc <modulename>               # 比如说: pydoc  
</div>

【帮助】
$ 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. 
</div>

【参数 -p】在本地机器上,按照给定的端口启动HTTP,
D:\>python -m pydoc -p 1234 #比如说: 端口为1234
pydoc server ready at http://localhost:1234/
pydoc server stopped
</div>

在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 
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 
</div>
【参数 -w】将指定模块的文本字符串生成HTML格式
比如说,在Window下面,执行下面命令:
D:\Learn\Python>python -m pydoc math -w math.html  # math是模块名,-w:写
</div>

那么在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 
</div>

执行命令:
D:\Learn\Python> python -m pydoc my_doc
</div>
执行结果:
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: 
&n

您可能想查找下面的文章:

  • Python文档生成工具pydoc使用介绍

相关文章

  • scrapy自定义pipeline类实现将采集数据保存到mongodb的方法
  • Python fileinput模块使用实例
  • python里大整数相乘相关技巧指南
  • 基于Python 的进程管理工具supervisor使用指南
  • python使用xmlrpclib模块实现对百度google的ping功能
  • 一键搞定python连接mysql驱动有关问题(windows版本)
  • 解密Python中的描述符(descriptor)
  • Python中处理unchecked未捕获异常实例
  • Python的Bottle框架中返回静态文件和JSON对象的方法
  • Python3遍历目录树实现方法

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Python通过websocket与js客户端通信示例分析
    • Python 字符串中的字符倒转
    • 200行自定义python异步非阻塞Web框架
    • Django实现自定义404,500页面教程
    • Python读写Json涉及到中文的处理方法
    • Python实现对excel文件列表值进行统计的方法
    • 理解Python中的类与实例
    • Pycharm学习教程(4) Python解释器的相关配置
    • 解析Mac OS下部署Pyhton的Django框架项目的过程
    • python3中set(集合)的语法总结分享

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有