Python中本身带有很多实用的工具,如pydoc。pydoc模块主要用来从Python模块中提取信息并生成文档。

使用方法

在Windows和Linux下的使用方法有些区别。

Windows

python -m pydoc <modulename>

如:

C:\>python -m pydoc module_test 

NB:module_test是自定义的模块,不要添加文件后缀。

Linux

pydoc <modulename>

如:

$ pydoc module_test

pydoc参数

$ pydoc -h
pydoc - the Python documentation toolpydoc <name> ...Show text documentation on something.  <name> may be the name of aPython keyword, topic, function, module, or package, or a dottedreference to a class or function within a module or module in apackage.  If <name> contains a '/', it is used as the path to aPython 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 currentdirectory.  If <name> contains a '/', it is treated as a filename; ifit names a directory, documentation is written for all the contents.$ 

无参数 <name>

显示文档,<name>可以是相查询的任何东西。如关键字、函数、模块、包等等。

C:\>python -m pydoc print
Help on built-in function print in module builtins:print(...)print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)Prints the values to a stream, or to sys.stdout by default.Optional keyword arguments:file:  a file-like object (stream); defaults to the current sys.stdout.sep:   string inserted between values, default a space.end:   string appended after the last value, default a newline.flush: whether to forcibly flush the stream.C:\>python -m pydoc random
Help on module random:NAMErandom - Random variable generators.DESCRIPTIONintegers--------uniform within rangesequences---------pick random elementpick random samplegenerate random permutationdistributions on the real line:------------------------------uniformtriangularnormal (Gaussian)lognormalnegative exponentialgamma
...

参数-k <keyword>

在可用模块中按关键字搜索。

C:\>python -m pydoc -k print
calendar - Calendar printing functions
email.quoprimime - Quoted-printable content transfer encoding per RFCs 2045-2047
.
encodings.quopri_codec - Codec for quoted-printable encoding.
json.tool - Command-line tool to validate and pretty-print JSON
lib2to3.fixes.fix_print - Fixer for print.
pprint - Support to pretty-print lists, tuples, & dictionaries recursively.
pstats - Class for printing reports on profiled python code.
quopri - Conversions to/from quoted-printable transport encoding as per RFC 1521
.
test.test_pprint
test.test_print
traceback - Extract, format and print information about Python stack traces.

参数-p <port>

在当前主机启用HTTP服务,使用指定的端口。

C:\>python -m pydoc -p 53241
Server ready at http://localhost:53241/
Server commands: [b]rowser, [q]uit
server> b
server>

如:

这时可以点击来跟踪链接进行查看相应的文档。

参数-w <name>

生成HTML文档。

首先编写一个模块,此外为class_test.py

"""
A simple test.
"""if __name__ == "__main__":print("hello")

然后执行如下:

C:\>python -m pydoc -w class_test
wrote class_test.html

此时在C盘根目录下生成了class_test.html文件,就可以在浏览器中进行查看了。

更多请参考Python的pydoc模块。

使用Pydoc生成文档相关推荐

  1. Python编程:使用pydoc生成文档注释

    pydoc是python自带的一个文档生成工具,可以提取注释 如果有三个引号的注释方法,会优先使用三个点的注释,其次才展示#号的注释 示例使用的代码pydoc_demo.py,包含一个函数,一个类 # ...

  2. django集成Sphinx,为项目自动生成文档

    Sphinx是一个工具,可以轻松创建智能和漂亮的文档,他与Python自带的pydoc是同一类产品,但比pydoc更加优秀,还有很多主题可以选择,平时在开发过程中,我们看到的第三方包的文档,基本上都是 ...

  3. Objective-C自动生成文档工具:appledoc

    作者 iOS_小松哥 关注 2016.12.13 15:47* 字数 919 阅读 727评论 10喜欢 35 由于最近琐事比较多,所以好久没有写文章了.今天我们聊一聊Objective-C自动生成文 ...

  4. Objective-C 自动生成文档工具:appledoc

    来源:iOS_小松哥 www.jianshu.com/p/fd4d8d6b6177 如有好文章投稿,请点击 → 这里了解详情 由于最近琐事比较多,所以好久没有写文章了.今天我们聊一聊Objective ...

  5. java前端目录_[Java教程]前端那点事儿——Tocify自动生成文档目录

    [Java教程]前端那点事儿--Tocify自动生成文档目录 0 2016-06-29 22:00:07 今天偶然间看到文档服务器有一个动态目录功能,点击目录能跳转到指定的位置:窗口滑动也能自动更新目 ...

  6. 快速优雅的为React组件生成文档

    在开发React组件时我们通常需要处理2个问题: 实例化这个组件以便调试 为这个组件编写使用文档以便更好的让别人知道怎么使用这个组件 最原始的方法莫过于开发时建一个页面用于调试,开发完后再为其手写文档 ...

  7. linux c/c++ 代码使用 doxygen 自动生成文档

    www.doxygen.org 的使用非常方便,下面分成2步介绍一下 1. 注释风格,需要在c/c++代码中按照下面的风格添加注释,基本上还是很顺手的 C++的注释风格 主要使用下面这种样式:即在注释 ...

  8. 使用DocFX生成文档

    使用DocFX命令行生成文档 使用docfx 命令 1.下载 https://github.com/dotnet/docfx/releases 2.使用 创建初始项目 docfx init -q 此命 ...

  9. docwizard c++程序文档自动生成工具_如何开发一个基于 TypeScript 的工具库并自动生成文档

    为什么用 TypeScript? TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. Any ...

最新文章

  1. Paper4:Voxel-Based Extraction and Classification of 3-D Pole-Like Object From Mobile LIDAR Point Clo
  2. pythonis啥意思-isinstance在python中的意思是什么?
  3. java追加txt文件_java怎么追加写入txt文件
  4. Oculus cv1 input
  5. php ci base url,CodeIgniter中base_url问题
  6. Linux内核分析——进程的描述和进程的创建
  7. 微软实习期的我,纠正了一位高级开发人员的错误......
  8. Sentence2vec
  9. Java旅游网站源码+页面
  10. CSS 颜色代码大全
  11. ubuntu 20.04中火狐浏览器安装flash插件
  12. 鸿蒙系统反应很快吗,EMUI11对比未成形的鸿蒙系统反应速度:速度差距较大,但细节赢了...
  13. 今日小程序推荐:动态壁纸-你专属壁纸!
  14. 600度近视眼恢复方法_近视孩子的家长看看:600度以上近视可致盲,不花钱恢复视力法...
  15. 【研究生】学会这几步,还怕不会写硕士论文?
  16. win10无线投屏_miracast投屏的未来
  17. Spring(四)AOP的注解方式用法
  18. 网络协议分析软件Sniffer Pro 4.7.5 破解版
  19. 【小龙女陈妍希古装Win7主题】
  20. 稻盛和夫系列之活法一

热门文章

  1. PostgreSQL常用SQL优化技巧
  2. 原生小程序配置vant
  3. 解决Vue项目在iOS 10 报错 “Cannot declare a let variable twice: ‘r‘”
  4. 计算机应用基础演示文稿内容,计算机应用基础(题型版)——演示文稿.doc
  5. Jmeter - 使用Mail Reader Sampler读取Gamil的邮件
  6. Domino Web应用早就想到了环保
  7. Ajax学习:Ajax优缺点
  8. 用物理学和域知识训练“无标注样本的”神经网络( Outstanding Paper Award 优秀论文奖)
  9. BES(恒玄) 提示音解析
  10. java之waite()和sleep()方法的区别