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模块

最新文章

  1. MYSQL 5.7 无法启动(Could not open error log file errno 2)
  2. swift——uiwebview的使用
  3. ACM: hihicoder #1174 : 拓扑排序&#183;一 STL- queue
  4. 感冒了~ vs中py和vb实现一个小算法
  5. 第十二章 非对称加密算法-RSA
  6. OpenJudge就算概论-最长单词2【寻找句子内部最长的单词】
  7. 261. Graph Valid Tree
  8. arm linux kernel启动之start_kernel
  9. mysql 超时 问题处理
  10. python闭包以及装饰器
  11. Strongly connected(hdu4635(强连通分量))
  12. 避免IE执行AJAX时,返回JSON出现下载文件
  13. 微信小程序(有始有终,全部代码)开发--- 新增【录音】以及UI改进
  14. Hadoop MapReduce2.0(Yarn)
  15. Minimum setup for Apache+AD SSO
  16. 安装kylin的艰难历程
  17. 【原创】sizeof运算符总结
  18. Java调用第三方接口示范
  19. php解决前后端验证字符串长度不一致
  20. 【nodejs】让nodejs像后端mvc框架(asp.net mvc )一样处理请求--路由限制及选择篇(2/8)【route】

热门文章

  1. Ffmpeg 探测输入源类型
  2. SQLServer 2017安装时的错误:Polybase要求安装Oracle JRE 7更新51或更高版本
  3. https 加载问题
  4. JavaScript的join()
  5. 关于工作与生活——HP大中华区总裁孙振耀撰文谈退休并畅谈人生
  6. k8s集群日志
  7. C# .Net 下 x86使用大内存的处理
  8. Nginx (简体中文)
  9. scp命令需要指定端口时要紧跟在scp后
  10. 【基础版限时免费】致敬WebForms,ASP.NET Core也能这么玩!