- In this article lets try to understand how Python executes programs
Python Interpreter – The Begining
- Before getting into Python , lets understand what is Interpreter ?
- Interpreter is a software program/logic that transforms the code written by you into the format your machine can understand
- When you install python, it generates number of components and Python interpreter is part of it. (Python has lot of flavors, In this article lets restrict to CPython.)
- When you try to execute the python program, the following sequence of actions will be performed
- Your source code will be compiled into a format known as byte code
- The byte code is shipped for execution to Python Virtual Machine(PVM)
Byte Code Compilation
- Byte code compiled files are generally stored as pyc files
- From Python 3.2 onwards, the byte codes are stored in a sub directory named as
- This is performed to speed execute as Byte code can be run more quickly than original source code
- If the same program is executed for the second time, now the same byte code is reused by loading .pyc files
- Python will regenerate byte code
- When source code changes
- When version of python used is changed.
Python Virtual Machine
- It is runtime engine of python.
- Its a big code loop that iterates through the byte code instructions and carries out the operations accordingly