An interpreter is a program that allows other programs to run, which is one of the logic layers of software from the user-written code to the hardware of the computer, the virtualization technology. Python can be used as an interpreter package, Python code must run in the interpreter, so the smallest component of Python installed on the machine is the-interpreter and the supported libraries. This article is for the Windows platform only, add Python to the environment variable path, such as "C:\Python34", Python version 3.4, the same as below.
1, program writing
Python programming supports interactive and executable file Two, the former is the command line type instructions, enter immediately get execution effect, the latter is to write a suffix. PY contains the Python statement file name.py (called a module), the command to travel to the path of the file, type " Python name.py "is ready to run.
The Python system also provides a standard, free visual user interface that allows you to edit, run, browse, and debug Python programs on a separate interface. Idle can run on multiple platforms, such as Windows, Linux, and UNIX.
2,python program execution, optimization, and release
For the Python interpreter, the procedure runs:
(1) Bytecode compilation-bytecode is the bottom of the source code, and hardware platform-independent representation, can improve the speed of operation. If Python has permission to write files, the resulting bytecode is in the same directory as the. py file, and the suffix is. PYc. If your program is not modified after compiling, Python skips the compile step and loads the bytecode file directly, and Python checks to see if the file is modified by comparing the source file with the timestamp of the bytecode file. If Python does not have write permissions, the bytecode is generated in memory, discarded after the program ends-that is, each execution is compiled.
(2) Python virtual machine-bytecode once generated will be sent to the Python virtual machine (PVM) execution, PVM is explained, s run a large loop of bytecode instruction. When the Python virtual machine starts execution, it performs some initialization, and finally enters the Pyeval_evalframex function, which is to read the compiled bytecode continuously and execute the process like CPU execution instructions. Inside the function is basically a switch structure that executes different code depending on the bytecode.
As the standard Python execution process, called CPython, it runs the fastest, most complete, and most robust. In fact, the execution of Python is changing over time, and two variants are Jython and IronPython. Jython is designed to integrate with the Java language, contain Java classes, compile Python source code to form Java bytecode, and map to Java virtual machines for seamless integration with Java. IronPython's design philosophy is to let Python integrate with the. NET Framework on the Windows platform and the applications written by the corresponding Linux open source Mono, developed by Microsoft.
In Python development, there are also some optimization systems that optimize the basic execution modules, trying to improve the speed of Python, such as Psyco real-time compilers and Shedskin C + + converters. The Psyco real-time compiler, which needs to be acquired and installed separately, is an extension of the bytecode execution module and is a PVM enhancement tool that collects and uses information to make the Python program execute while some bytecode is converted to the underlying true binary machine code, thus increasing the speed of operation. Psyco currently only generates binary machine code for the Intel X86 architecture, supporting Linux, Windows, Mac operating systems. The Shedskin C + + Converter attempts to convert the Python code into C + + code and then compiles the C + + code into machine code using the C + + compiler.
In addition, third-party tools "Freeze binaries" (Frozen binary) are required if you need to generate binary code that can be executed independently by the Python program. Frozen binary Packages Python program bytecode, PVM, and any required supporting files into a single package to form an executable binary that can be distributed. The free tool has py2exe,linux for Windows platforms, Pyinstaller for UNIX platforms, and more.
Python Learning Notes (ii) PYTHO interpreter and program development and execution process