【发布时间】:2013-08-07 04:03:03
【问题描述】:
我想看看 python deque 类。当我检查 the source code 时,我在第 10 行发现了以下内容
from _collections import deque, defaultdict
我在哪里可以找到这个 _collections 模块?我搜索了我的 python 源代码副本,但找不到它。
这门课在哪里?
【问题讨论】:
标签: python
我想看看 python deque 类。当我检查 the source code 时,我在第 10 行发现了以下内容
from _collections import deque, defaultdict
我在哪里可以找到这个 _collections 模块?我搜索了我的 python 源代码副本,但找不到它。
这门课在哪里?
【问题讨论】:
标签: python
【讨论】:
_collections 是根据此答案的类的私有实现:"Private" (implementation) class in Python。
由于是私有的,我认为您无法访问其 Python 源代码,但您可以查看 C 实现 here。
【讨论】:
_collections 是一个用 C 语言实现的模块,用于支持主要的 collections python 模块;因为它需要是一个独特的、独立的模块,所以使用了“内部”名称。毕竟,这只是一个实现细节,不是公共 API 的一部分。
现在CPython源码(包括内置模块)是hosted on Github,所以你可以找到集合模块源码here。
对于collections.abc 模块,请参阅here。
【讨论】: