PY is the source file, PYc is the source file compiled file, Pyo is the source file optimization compiled file, PYD is written in other languages of the Python library
Python is not entirely an explanatory language, it is compiled, the source py file is compiled into PYC or PYO, and then executed by the Python virtual machine, compared to the Py file, compiled into PYC and Pyo essentially and PY is not much different, Just for this module loading speed increased, and did not improve the execution speed of the code, usually do not have to actively compile the PYc file, the document said that as long as the import model is called model.py will be compiled into PYC and then loaded
1. If you need a special separate compilation, you only need to use Py_complie This module is OK, as follows
Import Py_compile
py_compile.compile (R ' H:\game\test.py ')
compile function Prototypes:
compile (file[, cfile[, dfile[, Doraise]])
file indicates the path of the py file that needs to be compiled
The CFile represents the compiled PYC file name and path, which by default is a byte code that adds C or o,o directly after the file file name
dfile error message saved path
doraise can be two values, true or FALSE, if true, a pycompileerror will be thrown, or if there is an error in compiling the file, there will be a fault that is displayed by default in Sys.stderr without throwing an exception
2. If you want to compile all the py files under a folder, use the following command
Import Compileall
Compileall.compile_dir (Dirpath)
Dirpath is the absolute path to the folder we are compiling
3. If you want to compile the Pyo file
compiled into Pyo is performed Python-o-M py_compile file.py in the console
where file.py is the source file we're compiling.
Python py, PYc, PYO, PYD file differences