简体   繁体   中英

Python Execution flow

I just need to know How the python executes its code.

I am not asking the code flow instead of how it converts the python code to the machine code that runs on the CPU.

While converting code to machine code, is it uses any compiler?

Because it saves.pyc file but Python is an interpreter.

The interpreter is different from the compiler.

The interpreter also converts the high level language code to the machine code.

What is the reason for the python uses the compiler?

After creating the.pyc file then, how and, when it will use this compiled file.

Please do not mark this question as duplicate... I searched for the answer but so many answers say only about the control flow of the program

Hope this helps.

Step 1: The interpreter reads a python code or instruction. Then it verifies that the instruction is well formatted, ie it checks the syntax of each line.If it encounters any error, it immediately halts the translation and shows an error message.

Step 2: If there is no error, ie if the python instruction or code is well formatted then the interpreter translates it into its equivalent form in intermediate language called “Byte code”.Thus, after successful execution of Python script or code, it is completely translated into Byte code.

Step 3: Byte code is sent to the Python Virtual Machine(PVM).Here again the byte code is executed on PVM. If an error occurs during this execution then the execution is halted with an error message.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM