Justin Noor3,692 Points
Why are some python libraries written in C?
I've never understood why many Python libraries, such as the datetime library, are written in C. I thought Python is a language on its own. Can anyone shed some light on this?
For example if you go to the Python docs and look at the datetime library, and click on the source code at the top left, it will take you to the Mercurial/CPython library page. What is CPython?
Jacob Herrington15,835 Points
The most popular implementation of Python is CPython which is written in C - meaning that the interpreter is written in C. Therefore, if you are using CPython it is possible to add features to your Python code with C. In a manner of speaking, by writing C code you are able to extend CPython itself which allows you to do things like add a new kind of Object.
Here are the source files for CPython on GitHub. If you'd like to see what I mean.
If you are interested in other implementations of Python including a Java implementation and a mind boggling version of the Python interpreter written in Python itself, here is some documentation to introduce you to the concept.
Furthermore, if you'd like to use C with Python yourself, this might interest you.