-2

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

  • 3
    Welcome to Stack Overflow! Your question is too broad. Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the [How to Ask](https://stackoverflow.com/help/how-to-ask) page for help clarifying this question. – Selcuk Oct 16 '19 at 06:44
  • 2
    you can start here e.g. https://stackoverflow.com/questions/6889747/is-python-interpreted-or-compiled-or-both – radoh Oct 16 '19 at 06:48

1 Answers1

1

Hope this helps.

Step 1 : The interpreter reads a python code or instruction. Then it verifies that the instruction is well formatted, i.e. 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, i.e. 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.