less than 1 minute read

What happens when you run Python Code

Heres the flow:

  • You download python
  • But you are actually downloading 3 things
    • the cpython compiler
    • the cpython virtual machine (just a C program)
    • the python library
  • You write python code
  • you run python3 my_python_file.py on your command line
  • the cpython compiler compiles your python code to bytecode
  • and saves the bytecode to a file called my_python_file.pyc
  • the cpython virtual machine then interprets the my_python_file.pyc file line by line

the bytecode interpreter is a loop that goes round and iterates over the file until there are no more commands to execute.

pretty neat!

Updated: