Python Inner Working
Is Python interpreted language or compiled language?
Behind the scenes when we write code in python and execute it
So basically below are the process or steps happen when we execute any .py file :-
First our whole python code is Compiled into Byte code.
๐กDON'T THINK THAT BYTE CODE IS MACHINE CODE. MACHINE CODE IS THE CODE WHICH IS DIRECTLY FEED TO ANY HARDWARE. BYTE CODE IS PLATFORM INDEPENDENT CODE.๐กByte code is sometimes called low level code also. When any big company wants to make their execution faster in cloud , they simply convert scripts into Byte Code and that's it Done. And they simply feed this Byte Code to Python Virtual Machine.๐๐กOne thing to know here is that Byte Code executed faster than simple python scripts as Syntax error checking , Attribute error checking , Name error checking , etc. has been done by interpreter.๐กAnd Byte Code is stored in .pyc ( Compiled Python ) file. It's naming convention is based on file name from which we import any method and python version which we are using. For Ex. - settings.cpython-312 , where settings is the filename and version is 3.12. Cpython is the standard implementation of python and mostly used version. Other than Cpython we have IronPython , Jython , PyPy , Stackless Python , MicroPython , etc.For converting Byte Code into machine understandable language or machine code , we have Python Virtual Machine ( PVM ) which is provided by python community and every company uses it and do their work.
๐กPVM is nothing but just a code loop which iterates again and again.And one interesting folder is created whenever we import some method from any other module or file. Its name is __pycache__. This folder consist of .pyc files and if you do change in existing code .pyc file will be created again and these changes are merged with existing one.
I am attaching one video here from one of the best tutorial I have found on Youtube.๐๐
So that's it for this article and if you find it useful , don't forget to like this article and follow me on LinkedIn.
Subscribe to my newsletter
Read articles from Ankush Ladani directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by