在Python中有很多很好的工具来生成字符串文档(docstring),比如说: epydoc、doxygen、sphinx,但始终觉得pydoc还是不错的工具,用法非常简单,功能也算不错,本文主要介绍pydoc.

pydoc是Python自带的模块,主要用于从python模块中自动生成文档,这些文档可以基于文本呈现的、也可以生成WEB 页面的,还可以在服务器上以浏览器的方式呈现!

【用法】

Windows下:

复制代码

代码如下:

D:\>python -m pydoc

# 比如说: python -m pydoc math

-m参数:Python以脚本的方法运行模块

Linux/Unix下:

复制代码

代码如下:

$ pydoc

# 比如说: pydoc

【帮助】

复制代码

代码如下:

$ pydoc -h

pydoc - the Python documentation tool

pydoc

...

Show text documentation on something.

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

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

Search for a keyword in the synopsis lines of all available modules.

pydoc -p

Start an HTTP server on the given port on the local machine.

pydoc -w

...

Write out the HTML documentation for a module to a file in the current

directory.  If

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

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

【参数 -w】将指定模块的文本字符串生成HTML格式

比如说,在Window下面,执行下面命令:

复制代码

代码如下:

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

'''

return x * x

执行命令:

复制代码

代码如下:

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

执行结果:

复制代码

代码如下:

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

DATA

__authors__ = 'Alice & Fred'

__license__ = 'Copyright...'

__version__ = 'version 1.10'

VERSION

version 1.10

执行命令:

复制代码

代码如下:

d:\Learn\Python>python -m pydoc -w my_doc my_doc.html

wrote my_doc.html

no Python documentation found for 'my_doc.html'

执行结果:

python自带的文档生成工具_Python文档生成工具pydoc使用介绍相关推荐

  1. python自动翻译小工具_Python实现翻译小工具

    一.背景 利用Requests模块获取有道词典web页面的post信息,BeautifulSoup来获取需要的内容,通过tkinter模块生成gui界面. 二.代码 git源码地址 Python实现翻 ...

  2. python自带intertool模块找不到_Python itertools模块:生成迭代器(示例分析)

    1 itertools 模块中主要包含了一些用于生成迭代器的函数.在 Python 的交互式解释器中先导入 itertools 模块,然后输入 e for e in dir(itertools) if ...

  3. python帮助文档在哪_python文档在哪里

    对于Python中一些不清楚的模块,可以通过文档学习如何使用,但是python文档在哪里呢?这个问题我们可以使用Python命令进行查看. 方法一 在python命令行输入以下内容help(time) ...

  4. python帮助文档在哪_python文档之查看帮助文档方法

    准备 使用time模块,使用time模块的localtime函数,使用range类 在已经分清模块,函数,类的情况下开始测试 方法一 在python命令行输入以下内容help(time) # 很详细的 ...

  5. python自带intertool模块找不到_Python itertools模块详解

    这货很强大, 必须掌握 基本是基于文档的翻译和补充,相当于翻译了 itertools用于高效循环的迭代函数集合 组成 总体,整体了解 无限迭代器 复制代码代码如下: 迭代器 参数 结果 例子 coun ...

  6. python生成验证码_python之验证码生成(gvcode与captcha)

    今天向大家总结一下python在做项目时用到的验证码生成工具:gvcode与captcha gvcode 全称:graphic-verification-code 安装: pip install gv ...

  7. python随机生成车牌_Python实现随机生成任意数量车牌号

    之前做课设的时候舍友遇到了需要生成500w量级车牌号的问题,于是我便写了一个随机生成车牌号的程序,希望各位采纳. 注:Python实现 import random def chepaihao(len= ...

  8. python批量生成图_python图像处理-批量生成纯色图片

    上一篇文章,是基于现有的图片处理的,那要如何通过代码直接生成图片呢. 生成一张纯色的图片 先设置图片的颜色,接着利用Image模块的new方法新生成一张图片,png格式的图片需要设置成rgba,类似的 ...

  9. python随机生成列表_python 实现快速生成连续、随机字母列表

    0.摘要 本文介绍了生成连续和随机字母表的方法,用于快速生成大量字母数据. 主要使用chr()函数,将数字通过ASCII表转换为相应字母. 1.chr() 函数 chr() 用一个范围在 range( ...

最新文章

  1. LINQ : IEnumerableT and IQueryableT区别
  2. 阿里某员工:年终奖到手,再见996
  3. Python_note4 程序控制结构+random库的使用
  4. Java中sql_Java中sql都有哪些
  5. JPA中实现双向一对多的关联关系
  6. mysql 按月建表_MySQL之存储过程按月创建表
  7. @程序员,你的 996,可能是给公司无能的管理背锅
  8. html点线面制作,利用HTML5绘制点线面组成的3D图形的示例_html5教程技巧
  9. Scala学习笔记(六):Scala程序
  10. fzu2181(点的双连通分量+求奇环)
  11. 华为移动wifi显示无服务器,华为移动wifi设置方法
  12. 这才是最简单的php+mysql+apache+bluefish+mysqlworkbench配置教程
  13. 解决Ubuntu插上耳机没声音
  14. Redis的expire(过期时间)
  15. properties文件的用法;utils类封装数据库连接、资源关闭、通用的增删改,以及两种通用的查询方法
  16. Vue.js中$refs{}获取DOM元素
  17. 西门子simens电脑模拟 828D840D 仿真
  18. 安装软件时,“Windows Installer Coordinator”一直循环
  19. 浅谈Android Architecture Components
  20. UnityC#字串如何获取换行符号-最基础的字串处理方法,也最容易常见错误

热门文章

  1. js之删除对象中的属性——delete、es6解构赋值、自执行匿名函数
  2. Saltstack_使用指南04_数据系统-Grains
  3. RPC框架与REST服务
  4. 【Python爬虫系列教程 25-100】小姐姐教大家对百度关键词收录数进行爬取,告诉你什么是有流量的关键词!
  5. 动态多目标优化算法:动态多目标狮群优化算法DMOLSO求解cec2015(提供完整MATLAB代码及所有测试问题的真实POF,含GD、IGD、HV和SP评价指标)
  6. 浅谈通过CMOS放电破解BIOS密码的原理
  7. autojs通知栏_基于Auto.js的蚂蚁森林智能脚本 (长期维护) (JavaScript语言)
  8. js点一个不行时,点两个:
  9. 筑基期第一式:深入Spring源码之第二节getBean全流程【循环依赖分析+扩展点分析】
  10. 教你如何使用shell批量查询ip归属