您的位置:首页技术文章
文章详情页

python 导包 `from _collections import deque, defaultdict`

【字号: 日期:2022-07-20 16:48:03浏览:41作者:猪猪

问题描述

昨天很偶然的看到这一行代码from _collections import deque

python 导包  `from _collections import deque, defaultdict`

我当时是在看python 的库文档来着,看到collections 的时候,我就去找deque的源代码,然后去找 _collections ,但是Lib目录下并没有找到,使用查找文件的时候发现目录Lib/site-packages/requests/packages/urllib3/_collections.py ,但是里面并没有有关于deque的代码,所有我就很好奇from _collections import deque ,这个 _collections 到底哪儿来的

问题解答

回答1:

这里

https://github.com/python/cpy...

回答2:

内建模块,类似以c扩展

In [4]: import _collections

In [5]: _collectionsOut[5]: <module ’_collections’ (built-in)>

回答3:

_collections是一个内置模块, 要从源码查找: Python-2.7.12/Modules/_collectionsmodule.c

标签: Python 编程