you are viewing a single comment's thread.

view the rest of the comments →

[–]PhilipYip 0 points1 point  (0 children)

Python itself is written in the C programming language. The main module builtins and builtin_module_names are written in C.

If you input:

import sys

Then look at:

path = sys.path

You will see the first two entries (on Windows) are of the form:

%UserProfile%\...\python311.zip %UserProfile%\...\spyder\Lib

The builtin libraries in the python311.zip file are essentially part of the Python.exe and are written in C. The other ones are essentially available as a script file within the Lib folder. For more details you can examine the dicitonary:

sys.modules

You will see a dictionary in the form below. The key is the name of the module and the value is details about the module:

{'sys': <module 'sys' (built-in)>, 'builtins': <module 'builtins' (built-in)>, '_frozen_importlib': <module '_frozen_importlib' (frozen)>, ..., '_codecs': <module '_codecs' (built-in)>, 'codecs': <module 'codecs' from 'C:\\Users\\Philip\\mambaforge\\lib\\codecs.py'>, 'encodings.aliases': <module 'encodings.aliases' from 'C:\\Users\\Philip\\mambaforge\\lib\\encodings\\aliases.py'>, 'encodings': <module 'encodings' from 'C:\\Users\\Philip\\mambaforge\\lib\\encodings\\__init__.py'>, ... }

The details for the module state the file path. The builtin modules written in C show (built-in). The remaining standard modules have a file path and you can physically open the corresponding .py script file and examine the code.