使用Pydoc生成文档
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生成文档的更多相关文章
- 使用 Swagger 自动生成 ASP.NET Core Web API 的文档、在线帮助测试文档(ASP.NET Core Web API 自动生成文档)
对于开发人员来说,构建一个消费应用程序时去了解各种各样的 API 是一个巨大的挑战.在你的 Web API 项目中使用 Swagger 的 .NET Core 封装 Swashbuckle 可以帮助你 ...
- 使用Ldoc给Lua生成文档
Ldoc介绍 LDoc是一个Lua的文档生成工具,过去,比较常用的Lua生成文档的工具是LuaDoc,可惜作者自从2008年之后就再也没有发布过新的版本了,说明作者基本上已经放弃维护了.而LDoc则是 ...
- 使用PhpDocumentor生成文档
一,网站根目录执行 $ composer require --dev phpdocumentor/phpdocumentor 二,进入vendor/bin/目录执行 $phpdoc -d D:\ser ...
- doxygen的使用(一)配置并生成文档
原创文章,欢迎阅读,禁止转载. doxygen是个好用的文档生成工具,他的强大功能有很多介绍,我就不说了.自带的chm帮助手册很全面,包括功能.注释规范.怎么配置.工具用法等.doxygen的用法共3 ...
- 配置WCF同时支持WSDL和REST,swaggerwcf生成文档
配置WCF同时支持WSDL和REST,SwaggerWCF生成文档 VS创建一个WCF工程,通过NuGet添加SwaggerWcf 创建完成后通过 程序包管理控制台 pm>Install-Pac ...
- ASP.NET Core 1.0 中使用 Swagger 生成文档
github:https://github.com/domaindrivendev/Ahoy 之前文章有介绍在ASP.NET WebAPI 中使用Swagger生成文档,ASP.NET Core 1. ...
- 为Unity项目生成文档(二)
Unity项目生成文档 接着上篇文章:为Unity项目生成文档(一) .Net项目可在VS配置XML 我们可以在VS中通过配置来生成xml文件,但是unity的project,就算同样配置了xml文档 ...
- doc2vec 利用gensim 生成文档向量
利用gensim 直接生成文档向量 def gen_d2v_corpus(self, lines): with open("./data/ques2_result.txt", &q ...
- 使用eclipse生成文档(javadoc)
使用eclipse生成文档(javadoc)主要有三种方法:1,在项目列表中按右键,选择Export(导出),然后在Export(导出)对话框中选择java下的javadoc,提交到下一步.在Java ...
随机推荐
- view无限旋转
- (void) showRefreshAnimation { [UIView animateWithDuration: options:UIViewAnimationOptionCurveLinea ...
- 使Gallery时设置居左显示
Gallery中的图片默认是居中显示的.可是在非常多情况下我们须要它居左显示,这样做有一个简单方法.就是把Gallery的left设置为负多少,如以下的方法: Drawable drawable=ca ...
- 如何去掉MapReduce输出的默认分隔符
我们在用MapReduce做数据处理的时候,经常会遇到将只需要输出键或者值的情况,如context.write(new Text(record), new Text("")),这样 ...
- Dictionary及KeyValuePair使用
/// <summary> /// 除去数组中的空值和签名参数并以字母a到z的顺序排序 /// </summary> /// <param name="dicA ...
- Jquery跨域请求php数据(jsonp)
Jquery跨域请求php数据 我们一般用到ajax的时候是在同服务器下,一般情况下不会跨域,但有时候需要调用其他域名或ip下的数据的时候,遇到跨域请求数据的时候. 今天在工作中碰到javascrip ...
- 将普通用户添加至sudoers列表
编辑/etc/sudoers文件,在尾部添加如下内容: myusername ALL=(ALL) ALL myusername ALL=(ALL) NOPASSWD: ALL 其中需要将红色部分替换成 ...
- zip文件压缩
zip文件结构 上面中的每一行都是一个条目,zip文件就是由一个或者多个条目组成. 条目在Java中对应ZipEntry类 创建zip压缩文件 知 ...
- 好文章收藏--五分钟理解一致性哈希算法(consistent hashing)
一致性哈希算法在1997年由麻省理工学院提出的一种分布式哈希(DHT)实现算法,设计目标是为了解决因特网中的热点(Hot spot)问题,初衷和CARP十分类似.一致性哈希修正了CARP使用的简 单哈 ...
- IE 下 log 调试的一点不同
介绍一点IE下控制台调试与chrome的区别 数组 alert([1,2]) console.log([1,2]) console.log([1,2],"1,2") alert I ...
- Java 异常介绍
Java标准库内建了一些通用的异常,这些类以 Throwable 为顶层父类.Throwable又派生出 Error 类和 Exception 类. 错误:Error类以及他的子类的实例,代表了JVM ...