鱼C论坛

 找回密码
 立即注册
查看: 2814|回复: 3

[技术交流] Python 小技巧 055:Python 的 pydoc(1. 基本用法)

[复制链接]
发表于 2020-1-23 21:36:17 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
Python 的 pydoc(基本用法)


pydoc 是 Python 自带的一个文档生成工具,使用 pydoc 可以很方便的查看类和方法结构。pydoc 模块可以从 Python 代码中获取帮助信息(Docstring)。

今天就让我们来学学它的基本使用方法。

查看 Python 关键字及其用法

在命令行中输入 python -m pydoc keywords,可以查看当前 Python 版本的所有关键字(-m 指定 Python 将模块当做脚本执行):

1.png

(相当于在 Python Shell 中执行 help('keywords'))

Enter any keyword to get more help 说明可以通过 python -m pydoc keywords {关键字名} 来获取指定关键字的帮助信息。比如我想查看 nonlocal 关键字的帮助信息:

  1. > python -m pydoc keywords nonlocal

  2. Here is a list of the Python keywords.  Enter any keyword to get more help.

  3. False               class               from                or
  4. None                continue            global              pass
  5. True                def                 if                  raise
  6. and                 del                 import              return
  7. as                  elif                in                  try
  8. assert              else                is                  while
  9. async               except              lambda              with
  10. await               finally             nonlocal            yield
  11. break               for                 not

  12. The "nonlocal" statement
  13. ************************

  14.    nonlocal_stmt ::= "nonlocal" identifier ("," identifier)*

  15. The "nonlocal" statement causes the listed identifiers to refer to
  16. previously bound variables in the nearest enclosing scope excluding
  17. globals. This is important because the default behavior for binding is
  18. to search the local namespace first.  The statement allows
  19. encapsulated code to rebind variables outside of the local scope
  20. besides the global (module) scope.

  21. ......
复制代码


查看 Python 当前可被导入的所有模块

在命令行输入 python -m pydoc modules,可以查看当前 Python 可被导入的所有模块(包括第三方模块):

1.png

(相当于在 Python Shell 中执行 help("modules"))

查看 Python 内置函数、模块及包的文档

查看 Python 内置函数、模块和包的方法很简单,只需要输入 python -m pydoc {函数名 \ 模块名 \ 包名} 命令:

1.png

1.png

1.png

本帖被以下淘专辑推荐:

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-1-24 17:09:17 From FishC Mobile | 显示全部楼层
来抢沙发了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-1-24 17:10:37 From FishC Mobile | 显示全部楼层
第一个图片下,多打了一个括号
@zltzlt
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-1-24 18:06:29 | 显示全部楼层
本帖最后由 zltzlt 于 2020-1-24 18:22 编辑
_2_ 发表于 2020-1-24 17:10
第一个图片下,多打了一个括号
@zltzlt


没有,你视力有问题

搜狗截图20200124180952.png
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-5-26 10:40

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表