What is the format of python source code after being converted by the interpreter?

Release: 2020-05-10 17:07:20
Original
5713 people have browsed it

What is the format of python source code after being converted by the interpreter?

#The format of the python source code converted by the interpreter is ".pyc".

When we write Python code, what we get is a text file with a .py extension that contains Python code. To run the code, you need the Python interpreter to execute the .py file.

The interpreter consists of a compiler and a virtual machine. The compiler is responsible for converting the source code into a bytecode file, and the virtual machine is responsible for executing the bytecode.

So, interpreted languages actually also have a compilation process, but this compilation process does not directly generate target code, but intermediate code (bytecode), and then the virtual machine interprets and executes the bytes line by line. code.

After executing python XX.py, the Python interpreter will be started. The compiler of the python interpreter will compile (interpret) the .py source file into bytecode to generate a PyCodeObject bytecode object and store it in memory. middle.

The virtual machine of the Python interpreter converts the bytecode objects in the execution memory into machine language. The virtual machine interacts with the operating system to enable the machine language to run on the machine hardware. After running, the python interpreter writes the PyCodeObject back to the pyc file.

pyc file, the file contains the magic number of python (to indicate the python version number used during compilation), the mtime of the source file (to keep the pyc and py files in sync), and the compiled code object.

Recommended:python video tutorial

The above is the detailed content of What is the format of python source code after being converted by the interpreter?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!