Python py, PYc, PYO, PYD file differences

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.