Learning_Python_Chapter_2_Part_1

Chapter 2
Part 1 of 2

Today, we are going to start chapter 2 and skipping a few points from chapter 1, don’t worry, I’ll cover them later. Let’s start with the most important concept.

 Introducing the Python Interpreter
 Firstly, what is an interpreter?
As we know, languages like Python are not platform dependent. That means, scripts that we are writing are compatible on windows,Linux or any other operating system.

Also, it is not hardware dependent; we can run a Python script on Intel chip or any other like AMD.

So, what give Python that ability?
“An interpreter is a kind of program that executes another program”

Woo... a program to run another program.

Designing or writing these type of systems are currently beyond our reach but what we can do now is, we can learn them or understand them and can use them. Simple!

The interpreter is a layer of software logic between your code and the computer hardware of your computer

When we install python on our machine, the components like interpreter and supporting libraries gets installed.
These components are machine dependent which makes our program independent.

If an interpreter is a program which runs python program then, in which language interpreter is written?

Designers write these things in C or set of Java classes and other required tools.

If we want to touch hardware programmatically then we have to use low-level languages

How to install Python on your computer?
  Installation can be understood by online steps:


If you get any issue while installation, comment it. So we can Google it together.

Program Execution

To write and run a Python script you should have perspective of a programmer and an interpreter. Both view offers importance in python programming.

IMPORTANT
How the program gets executed?
To understand all these concepts,
Consider the process of making Roti (a round flatbread),
       - We take wheat powder and water
    - Stir and mix the wheat powder with correct amount of water
      - Now we get a thick sticky  intermediate product. Lets call it dough
      - We bake this dough in circular shapes and gets the final product as a Roti

We can compare this example with python program execution,
         - Consider our source code as a  wheat powder
    - After performing compilation, that means after adding correct amount of water, we get an intermediate product as a ‘ByteCode’ i.e. dough of Roti
      - We run this ByteCode that means we process our dough to obtain the final product as a Roti i.e. a python application.

Let’s simplify the things,
      - Take a pen and a paper
    - Draw three consecutive bubbles separated by small distance and draw the arrows from first to second and second to third
   - Label the first bubble as Source Code, second as Bytecode and last bubble as ‘Runtime Application’
    - Consider if we write our program in xyz text file
   - Inside the first bubble write ‘xyz.py’ , in second xyz.pyc’ and inside the last bubble please write ‘PVM’ that means Python Virtual Machine (Most Important)

This is the diagram which will help you in this Learning Python journey.

Let’s understand the above words,
Source code: a program or a script

Byte Code: it is also a program which is obtained after compiling our source code, but it is ready-to-use as dough of Roti from our example. That means whenever we want to run an application without wasting time in source code compiling we can use a file which is already compiled and stored as a product for quick use and quick access.

Runtime application:  it is the final product,the output of our program or output obtained after processing.

.py (dot py extension): it is an extension given to our text file that means an extension to our source code. Py stands for python file.

.pyc (dot pyc extension);  pyc stands for compiled python file. We can say that it is the file format of ByteCode.

PVM: (Python Virtual Machine)
Let’s understand the concept of Virtual Machine in 5 min.
Here is the 3 min video


And 2 min for buffering and YouTube ads.

Once our program has been compiled to ByteCode, it gets shipped to PVM for execution.

PVM is just a big code that iterates through our ByteCode instructions. In short, it runs our program.

PVM is runtime engine of python and it is always there as a part of python system.

PVM is the last stage of our interpreter diagram.

All these stages and executions are hidden(abstracted) from programmers. Python implicitly performs these operations. Hence, keep our bubble diagram always in mind.

ByteCode compilation is an automatic operation and PVM is a part of python system that we have installed on our machine. We write and run the codes but Python is the main Hero who is performing logistics and transportation of all things throughout this process.
Thank you!
                           -Sh0ckwave88


Comments

Popular posts from this blog

Learning_Python_Chapter_1_Part_1

Learning_Python_Chapter_2_Part_2

Learning_Python_Chapter_1_Part_3