12

I wanted to have a look at the python deque class. When I checked the source code , I found the following at line 10

 from _collections import deque, defaultdict

where exactly can I find this _collections module? I searched on my copy of the python source, but couldn't spot it.

Where is this class located?

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
damon
  • 8,127
  • 17
  • 69
  • 114

3 Answers3

13

_collections is builtin extension module.

You can find source for _collection module here.

Setup.dist contains mapping between builtin extension module name to source file.

falsetru
  • 357,413
  • 63
  • 732
  • 636
1

_collections is a private implementation of a class according to this answer: "Private" (implementation) class in Python.

Being private, I don't think that you will be able to access its Python source but you can check out the C implementation here.

Community
  • 1
  • 1
  • 1
    In this case, `_collections` is a module implemented in C to support the main `collections` python module; because it needs to be a distinct, separate module an 'internal' name is used. It is but an implementation detail, after all, not part of the public API. – Martijn Pieters Aug 06 '13 at 09:03
1

These days the CPython source code (including built-in modules) is hosted on Github, so you can find the collections module source code here.

For the collections.abc module, see here.

Stuart Berg
  • 17,026
  • 12
  • 67
  • 99