简体   繁体   中英

How can I see the source code of deque module from Python's collections library?

I tried using inspect.getsource(deque) and while it works on other modules from collections, running it on deque throws an error "could not find class definition". Why does this happen only to deque and how can I see it's source code?

This one is implemented in C code for CPython, and the collections python module just imports that name . Depending on your Python version and installation, you may find somewhere on your system a file called _collections.so or _collectionsmodule.so which has the real implementation, but inspect.getsource is not really smart enough to figure that out.

You can find the sources here:

https://github.com/python/cpython/blob/3.7/Modules/_collectionsmodule.c

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM