Python Tutorials - Program Execution in Python, How to Program Execution is performed in Python


Program Execution in Python, How to Program Execution is performed in Python

Program Execution in python is a simplest way to write and run the python scripts on interactive prompt of any of the editor used to write the code and save it with .py extension and then run like this
python file_name.py hit enter

The Programmer’s View 


In the simplest way, a Python program is just a text file containing Python statements.
For example, the following file, named example.py, is the simplest way to write Python scripts, but it passes for a fully functional Python program:

>>>print('hello python world')
>>>print(3 ** 100)

The above file contains two Python print statements, which simply print a string ("hello python world") and a numeric expression result (3 to the power 100) to the output stream.

Python’s View

As like other programming languages the Python program also converts into something like a byte code and then also converts in machine code by something like a "virtual machine"

Byte code compilation

After compilation the Python source code converts into a Byte Code internally and you don't able to see it and sometimes the Byte Code converts for the piece of code individually and it is a secret code which is neither a source code nor a machine code, it is intermediate code and provide security and speed to the python programs execution.
The Byte Code can't be readable and it is look something like the combination of some special characters.

The Python Virtual Machine (PVM)

Once your program has been compiled to byte code , then it is send to generally known as the Python Virtual Machine (PVM). The PVM sounds more impressive than it is; really, it’s not a separate program it is inbuilt with the OS kernel, and it need not be installed by itself. In fact, the PVM is just a big loop that iterates through your byte code instructions, one by one, to carry out their operations. The PVM is wok as a real Machine but technically it is not a machine. The PVM is the run- time engine of Python. Technically, it’s just the last step of what is called the “Python interpreter.”


Performance implications

Readers with a background in fully compiled languages such as C and C++, Java, C# etc might notice a few differences in the Python model. One is, there is usually no "build" or “make” step in Python Execution, code runs immediately after it is written. Another is, Python byte code is not binary machine code. Byte code is a Python-specific representation of some hidden code.


In above figure -Python’s traditional run-time execution model, source code you type is translated or converted to byte code, which is then run or executed by the Python Virtual Machine. Your code is automatically compiled, but then it is interpreted.

{ 0 comments... read them below or add one }

Post a Comment