I'm currently learning Python and I want to gain a deeper understanding of how python works by reading its source code.
I could manually go to the directory where Python is installed and check out the source code
I was wondering, is it possible to read Python source code directly from IDE such as PyCharm?
I tried to control click
on a method name, even though it did bring me to the method definition page, it did not contain any implementation code
Edit 1
I understand a large of python (cpython to be exact) is implemented in c. Is there anyway to read the c code in IDE such as PyCharm?
These are mostly compiled sources which means only the bytecode is used by the Interpreter. Not all the functions are written in C, most of it is actually written in pure python. One way to view source is through terminal by using ipython . Alternatively you can find what you want, by using inspect.
Source code is the list of human-readable instructions that a programmer writes—often in a word processing program—when he is developing a program. The source code is run through a compiler to turn it into machine code, also called object code, that a computer can understand and execute.
By default, TextEdit stores files in Rich Text Format. That means you can do things like bold or italics, or even underline. But this is not suitable for writing source code. To change it, we're going to go over to TextEdit, choose Preferences, and then we're going to choose plain text under the Format section.
Normally PyCharm does what you want, unless the Ctrl+Click leads you to a C function. In this case you will get only minimal information on the function signature and return value, etc., just like you show in your post. built-ins are mainly written in C for an efficiency reason, so if you want to see the C code you'll have to download CPython source code and dive into it. Another alternative would be to download the PyPy source code and take a look at it. Still, you can use PyCharm to read code from modules written in Python in the standard library and that would be helpful in your learning process. Believe me, you'll find good quality code there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With