我需要为继承到deque的类添加功能,但更喜欢查看collections.deque中的代码来实现新的类final.
>>> from _collections import deque, defaultdict >>> inspect.getfile(deque) '/usr/lib/python2.7/collections.pyc' >>> inspect.getfile(collections) '/usr/lib/python2.7/collections.pyc' >>> inspect.getfile(_collections) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/inspect.py", line 403, in getfile raise TypeError('{!r} is a built-in module'.format(object)) TypeError: is a built-in module >>>
我在哪里可以找到collections.deque的源代码?这是源集合,但不包含collections.deque.- > http://hg.python.org/cpython/file/2.7/Lib/collections.py
_collections
是一个内置模块.
在CPython中,这个模块是用C语言编写的:https: //github.com/python-git/python/blob/master/Modules/_collectionsmodule.c
但PyPy中有一个纯python实现:https: //bitbucket.org/pypy/pypy/src/default/lib_pypy/_collections.py