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 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. $

无参数 <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: NAME
random - Random variable generators. DESCRIPTION
integers
--------
uniform within range sequences
---------
pick random element
pick random sample
generate random permutation distributions on the real line:
------------------------------
uniform
triangular
normal (Gaussian)
lognormal
negative exponential
gamma
...

参数-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. 使用 Swagger 自动生成 ASP.NET Core Web API 的文档、在线帮助测试文档(ASP.NET Core Web API 自动生成文档)

    对于开发人员来说,构建一个消费应用程序时去了解各种各样的 API 是一个巨大的挑战.在你的 Web API 项目中使用 Swagger 的 .NET Core 封装 Swashbuckle 可以帮助你 ...

  2. 使用Ldoc给Lua生成文档

    Ldoc介绍 LDoc是一个Lua的文档生成工具,过去,比较常用的Lua生成文档的工具是LuaDoc,可惜作者自从2008年之后就再也没有发布过新的版本了,说明作者基本上已经放弃维护了.而LDoc则是 ...

  3. 使用PhpDocumentor生成文档

    一,网站根目录执行 $ composer require --dev phpdocumentor/phpdocumentor 二,进入vendor/bin/目录执行 $phpdoc -d D:\ser ...

  4. doxygen的使用(一)配置并生成文档

    原创文章,欢迎阅读,禁止转载. doxygen是个好用的文档生成工具,他的强大功能有很多介绍,我就不说了.自带的chm帮助手册很全面,包括功能.注释规范.怎么配置.工具用法等.doxygen的用法共3 ...

  5. 配置WCF同时支持WSDL和REST,swaggerwcf生成文档

    配置WCF同时支持WSDL和REST,SwaggerWCF生成文档 VS创建一个WCF工程,通过NuGet添加SwaggerWcf 创建完成后通过 程序包管理控制台 pm>Install-Pac ...

  6. ASP.NET Core 1.0 中使用 Swagger 生成文档

    github:https://github.com/domaindrivendev/Ahoy 之前文章有介绍在ASP.NET WebAPI 中使用Swagger生成文档,ASP.NET Core 1. ...

  7. 为Unity项目生成文档(二)

    Unity项目生成文档 接着上篇文章:为Unity项目生成文档(一) .Net项目可在VS配置XML 我们可以在VS中通过配置来生成xml文件,但是unity的project,就算同样配置了xml文档 ...

  8. doc2vec 利用gensim 生成文档向量

    利用gensim 直接生成文档向量 def gen_d2v_corpus(self, lines): with open("./data/ques2_result.txt", &q ...

  9. 使用eclipse生成文档(javadoc)

    使用eclipse生成文档(javadoc)主要有三种方法:1,在项目列表中按右键,选择Export(导出),然后在Export(导出)对话框中选择java下的javadoc,提交到下一步.在Java ...

随机推荐

  1. destroy其他所有activity

    Intent intent = new Intent(ActivityA.this, ActivityB.class);intent.setFlags(Intent.FLAG_ACTIVITY_NEW ...

  2. OpenLayers加载天地图

    openlayer 是基于JavaScript的webGIS库 ,通过openlayer可以很容易的调用地图,并做相应的操作. 在head中载入openlayer的js文件: <link rel ...

  3. phpexcel导入xlsx文件报错xlsx is not recognised as an OLE file 怎么办

    最初的做法  代码如下 1 include 'classes/PHPExcel/IOFactory.php'; 2 $inputFileName = $target; 3 $objReader = n ...

  4. HTML DOM节点的增删改查

    上篇博客中,我们已经初步接触了DOM基础,可是我们学习是为了可以更好地应用,今天我们就来看看DOM节点的增删改查. 无论在哪里,我们想要操作一个东西,总是应该先去获得它.那么我们怎么获得呢? HTML ...

  5. k8s部署nginx集群

    环境: 两台虚拟机, 10.10.20.203 部署docker.etcd.flannel.kube-apiserver.kube-controller-manager.kube-scheduler ...

  6. WPF 获取控件模板中的控件

    DG是控件名称public T GetVisualChild<T>(DependencyObject parent, Func<T, bool> predicate) wher ...

  7. onCreate中获得控件的大小

    @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setC ...

  8. mysqldump命令使用详解

    mysqldump是一个数据库备份程序 用法:mysqldump [options] [db_name [tbl_name ...]] 描述:mysqldump是一个客户端逻辑备份的工作,备份的SQL ...

  9. [Catalan数]1086 栈、3112 二叉树计数、3134 Circle

    1086 栈 2003年NOIP全国联赛普及组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 栈是计算机中 ...

  10. nginx + uWSGI 为 django 提供高并发

    django 的并发能力真的是令人担忧,这里就使用 nginx + uwsgi 提供高并发 nginx 的并发能力超高,单台并发能力过万(这个也不是绝对),在纯静态的 web 服务中更是突出其优越的地 ...