/  Technology   /  Python execution style
Python Execution Style

Python execution style

Python is very easy and high-level programming language. Python was started as a hobby project by Guido Van Rossum and was first released in 1991. In an interview, Guido compares Python to languages like Java or Swift and says that while the latter two are a great choice for software developers — people whose day job is programming, but Python was made for people whose day job has nothing to do with software development but they code mainly to handle data.


A general-purpose language, Python is powering large group of many companies like Netflix and Instagram. When you started learning Python you might have heard of words like- compiled vs interpreted, bytecode vs machine code, dynamic typing vs static typing, garbage collectors, etc. Python is described as an interpretedhigh-levelgeneral-purpose programming language. It is dynamically typed and garbage-collected.


Interpreted Languages


When you write C/C++ programming languages you need to compile them. Compilation is the process of translating your human understandable code to machine understandable code. CPU directly executes this Machine Code. After successful compilation, code generates an executable file which runs the operations in your code step by step.

But Python is an interpreted language and not a compiled one. Python code, written in .py file is first compiled to what is called bytecode which is stored with a .pyc or .pyo format. The .pyc file will be regenerated only when the source code is updated.

This bytecode is a low-level set of instructions that can be executed by an interpreter.  In most PCs, Python interpreter is installed at /usr/local/bin/python3.8. Instead of executing the instructions on CPU, bytecode instructions are executed on a Virtual Machine.

As long as the Python bytecode and the Virtual Machine have the same version, Python bytecode can be executed on any platform (Windows, MacOS, etc). Hence platform independency is the most popular advantage of interpreted languages.

Dynamic typing is an additional advantage of Python. C/C++ languages are static-typed i.e., you need to declare the variable type initially. Any discrepancies will be checked during compile time. But in Python, it is the job of the interpreter to check the validity of the variable types and operations performed.

Python is often accused of being ‘slow’ because the interpreter has to do extra work to have the bytecode instruction translated into a form that can be executed on the machine.

In your project a folder named  __pycache__ is created automatically.

   - __pycache__
       - preprocess.cpython-36.pyc
   - preprocess.py

As you can see .pyc file above.  The .pyc extension tells us that the file contains bytecode for preprocess.py.

The names cpython denotes the type of interpreter. CPython means that the interpreter was implemented in C language. Similarly, JPython is a Python interpreter implemented in Java.

This folder is created at the very first place, this is to increases the speed of the Python program.

Leave a comment