How to read Python source code directly from the IDE

I am currently learning Python, and I want to get 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 the source code

enter image description here

I was wondering if it is possible to read Python source code directly from an IDE such as PyCharm?

I tried the control clickname of the method, although it brought me to the method definition page, it did not contain any implementation code

enter image description here

Change 1

I understand that big python (more precisely, cpython) is implemented in c. Is there anyway to read the c code in an IDE such as PyCharm?

+6
source share
3 answers

, python C, . , . , , , , -. C, .

- ipython.

In [10]: import string
In [11]: string.lower??
Signature: string.lower(s)
Source:   
def lower(s):
    """lower(s) -> string

Return a copy of the string s converted to lowercase.

"""
return s.lower()
File:      /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/string.py
Type:      function

In [12]: import os

In [13]: os.system??
Docstring:
system(command) -> exit_status

Execute the command (a string) in a subshell.
Type:      builtin_function_or_method

, , inspect.getsource().

import inspect
import os
print (inspect.getsource(os))
# You should see the source code here

, .

, C, , , python . cpython/Objects. , C, .

, , . , .

+12

PyCharm , , Ctrl + Click C. .., . C , , C, CPython . PyPy . , PyCharm , Python , . , .

+5

, Python - . , . , , , . Python.

+1
source

All Articles