【问题标题】:finding _collections in python source在 python 源代码中查找 _collections
【发布时间】:2013-08-07 04:03:03
【问题描述】:

我想看看 python deque 类。当我检查 the source code 时,我在第 10 行发现了以下内容

 from _collections import deque, defaultdict

我在哪里可以找到这个 _collections 模块?我搜索了我的 python 源代码副本,但找不到它。

这门课在哪里?

【问题讨论】:

    标签: python


    【解决方案1】:

    _collections 是内置扩展模块。

    您可以找到_collection模块here的来源。

    Setup.dist 包含内置扩展模块名称到源文件之间的映射。

    【讨论】:

      【解决方案2】:

      _collections 是根据此答案的类的私有实现:"Private" (implementation) class in Python

      由于是私有的,我认为您无法访问其 Python 源代码,但您可以查看 C 实现 here

      【讨论】:

      • 在这种情况下,_collections 是一个用 C 语言实现的模块,用于支持主要的 collections python 模块;因为它需要是一个独特的、独立的模块,所以使用了“内部”名称。毕竟,这只是一个实现细节,不是公共 API 的一部分。
      【解决方案3】:

      现在CPython源码(包括内置模块)是hosted on Github,所以你可以找到集合模块源码here

      对于collections.abc 模块,请参阅here

      【讨论】:

        猜你喜欢
        • 2015-04-23
        • 2013-10-28
        • 1970-01-01
        • 1970-01-01
        • 2012-01-26
        • 1970-01-01
        • 2015-03-09
        相关资源
        最近更新 更多