In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Introduction:
There are three file types commonly used in python
1. Source code py
two。 Byte code pyc
3. Optimize the code pyo
Source code:
Python source code files with the extension "py" are interpreted by the python program and do not need to be compiled
Byte code:
Python source file is compiled to generate a file with the extension "pyc", which is used to hide the code and improve the loading speed of the compilation method:
Generate a single pyc file:
Method 1: code mode
# vim compile.py
Import py_compile
Py_compile.compile ("hello.py")
Method 2: command line mode
# python-m py_compile hello.py
-m is equivalent to import in a script
Batch generate pyc files:
Generally speaking, our projects are in a directory, generally speaking, we don't just compile a py file, but we need to compile all the py files under the entire folder into pyc files. Python provides us with another module: compileall. The method of use is as follows:
Method 1: code mode
Import compileall
Compileall.compile_dir (ringing Universe Game`)
Method 2: command line mode
# python-m compileall / root/src/
Optimize the code:
The optimized compiled file with the extension "pyo" pyo is the optimized compiled program, and it can also improve the loading speed. For embedded systems, compiling the required modules into pyo files can reduce the capacity, which is essentially no different from pyc.
Optimization method:
# python-O-m py_compile hello.py
Note: bytecode and optimized code cannot be executed directly and can only be run with the interpreter
How to perform correctly:
# python hello.pyc
# python hello.pyo
Error execution method:
#. / hello.pyc / / an error will be reported in this way
Valgus:
1. What is a pyc file: pyc is a binary file that is compiled from a py file and generated. It is a byte code,py file that loads faster after it becomes a pyc file, and pyc is a cross-platform bytecode that is executed by a python virtual machine, which is similar to the concept of a virtual machine in JAVA or .NET. The content of pyc is related to the version of python, different versions of the compiled pyc file is different, 2.5 compiled pyc file, 2.4 version of python can not be executed.
two。 Why do you need pyc files: this requirement is obvious, because py files can see the source code directly, and if you are developing commercial software, it is impossible to leak the source code, right? So you need to compile it to pyc and then release it. Of course, pyc files can also be decompiled, different versions of the compiled pyc files are different. According to the opcode provided in the python source code, you can decompile the py file source code according to the pyc file. You can find a tool to decompile the python2.3 version of the pyc file on the Internet, but the tool will be charged from python2.4, if you need to decompile a new version of the pyc file. You need to do it yourself, but you can modify the opcode file in python's source code and recompile python to prevent lawbreakers from cracking it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.