您的位置:首頁技術文章
文章詳情頁

python 導包 `from _collections import deque, defaultdict`

瀏覽:94日期:2022-07-20 16:48:03

問題描述

昨天很偶然的看到這一行代碼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 編程
国产综合久久一区二区三区