获取标准库模块列表?

3

我希望你能提供标准库中所有模块的列表。

至于关键字,我通过以下方式获取它们:

import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']

对于内置函数:

>>> dir(__builtins__)
['ArithmeticError', ..., 'super', 'tuple', 'type', 'vars', 'zip']

如何将相同的操作应用于在 Python 官方文档中找到的其他标准库名称。
# my desired result is this
['colletions', 'datetime', 'os', ... ]
# So will check them for reference anytime and anywhere.

1
调用 help('modules') 将会得到已安装模块的列表。 - cs95
@cᴏʟᴅsᴘᴇᴇᴅ 包括标准库中没有的东西。 - wim
1个回答

3

很不幸,没有标准库方法可以获取标准库列表。但是有一个第三方模块可以实现这个功能。通过 此链接 可以获取该模块。使用 pip install stdlib_list 命令安装后,执行以下代码:

>>> from stdlib_list import stdlib_list
>>> libs = stdlib_list()
>>> libs[-10:]
['xml.sax',
 'xml.sax.handler',
 'xml.sax.saxutils',
 'xml.sax.xmlreader',
 'xmlrpc.client',
 'xmlrpc.server',
 'zipapp',
 'zipfile',
 'zipimport',
 'zlib']

它的工作原理是通过抓取Python Sphinx文档来实现,因此非常可靠。请注意,标准库内容会随着不同版本的Python而改变,因此在使用此功能时应指定Python版本。如果未指定,则默认使用当前解释器版本。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接