当前位置:网站首页>What is PyC file
What is PyC file
2022-07-05 19:56:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
It's very simple , use python -m py_compile file.py
python -m py_compile /root/src/{file1,file2}.py Translate it into pyc file . You can also write a script to do this : Code:
import py_compile py_compile.compile(‘path’) //path Include .py Path to file name |
|---|
use python -O -m py_compile file.py
Translate it into pyo file . 1. Among them -m Equivalent to... In the script import, there -m py_compile Equivalent to import py_compile 2.-O If change to -OO Delete the corresponding pyo file , Specific help can be entered on the console python -h see
========================
from:http://blogold.chinaunix.net/u3/93255/showart_1944929.html
What is? pyc file
pyc It's a binary file , By py The file is compiled , Generated files , It's a kind of byte code,py File becomes pyc After the document , The loading speed has increased , and pyc It's a cross platform bytecode , By python The virtual machine to execute , This is similar to JAVA perhaps .NET The concept of virtual machine .pyc The content of , with python The version of , Compiled versions of pyc Documents are different ,2.5 Compilation of pyc file ,2.4 Version of python It can't be carried out .
What is? pyo file
pyo Is to optimize the compiled program python -O The source file can compile the source program into pyo file
What is? pyd file
pyd yes python Dynamic link library for .
Why pyc file
This demand is too obvious , because py You can see the source code directly , If you're developing business software , It's impossible to disclose the source code ? So it needs to be compiled as pyc after , Release it again . Of course ,pyc Files can also be decompiled , Compiled versions of pyc Documents are different , according to python Provided in the source code opcode, According to pyc Decompile the file to py File source code , You can find a decompile on the Internet python2.3 Version of pyc File tool , But the tool comes from python2.4 There will be a charge at the beginning , If you need to decompile a new version of pyc Word of the file , You need to do it yourself ( I don't have this ability for the time being ^–^), But you can modify it yourself python In the source code of opcode file , recompile python, So as to prevent criminals from cracking .
Generate single pyc file
python It's a good thing , It provides a built-in class library to implement py The file is compiled as pyc file , This module is py_compile modular .
It's very simple to use , As shown below , Directly in idle in , You can put one py The file is compiled as pyc The file .( Suppose that windows In the environment )
import py_compile
py_compile.compile(r’H:\game\test.py’)
compile The function prototype :
compile(file[, cfile[, dfile[, doraise]]])
file Indicates that you need to compile py Path to file
cfile Represents compiled pyc File name and path , The default is directly in file Add... After the filename c perhaps o,o Represents optimized bytecode
dfile This parameter cannot be understood in English , Please enlighten me greatly .( Despise Yourself ) original text :it is used as the name of the source file in error messages instead of file
doraise It can be two values ,True perhaps False, If True, It will trigger a PyCompileError, Otherwise, if there is an error compiling the file , There will be a mistake , The default display is sys.stderr in , Without throwing an exception
( come from python2.5 file )
Batch build pyc file
Generally speaking , Our projects are all in one directory , It's not like compiling just one py The file" , It needs to put the whole folder under py The files are compiled as pyc file ,python Another module is provided for us :compileall . How to use it is as follows :
import compileall
compileall.compile_dir(r’H:\game’)
You can also compile files in a directory directly from the command line , Such as :# python -m compileall /root/src/
This way game Catalog , And its subdirectories py The file is compiled as pyc The file . Hey , It's convenient enough . Take a look compile_dir Function description :
compile_dir(dir[, maxlevels[, ddir[, force[, rx[, quiet]]]]])
dir Indicates the location of the folder to compile
maxlevels Represents the number of levels of subdirectories that need to be recursively compiled , The default is 10 layer , That is to say, by default 10 In the layer subdirectory py The file is compiled as pyc
ddir I don't understand English , original text :it is used as the base path from which the filenames used in error messages will be generated.
force If True, Will be forced to compile to pyc, Even now pyc The document is up to date , It also forces compilation once ,pyc The file contains a timestamp ,python The compiler will decide... Based on time , Do you need to regenerate pyc file
rx Represents a regular expression , For example, you can exclude unwanted directories , Or only qualified directories can be compiled
quiet If True, After compiling , Not in standard output , Print out information
( come from python2.5 file )
summary
Use the above method , It's convenient to put py The file is compiled as pyc The file , In this way, part of the source code can be hidden , To ensure the python When doing commercial software , Ensure the safety of some , Keep learning , See how to modify opcode.
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/149996.html Link to the original text :https://javaforall.cn
边栏推荐
- IBM has laid off 40 + year-old employees in a large area. Mastering these ten search skills will improve your work efficiency ten times
- gst-launch的-v参数
- Microwave radar induction module technology, real-time intelligent detection of human existence, static micro motion and static perception
- Summer Challenge harmonyos - realize message notification function
- 安信证券在网上开户安全吗?
- S7-200SMART利用V90 MODBUS通信控制库控制V90伺服的具体方法和步骤
- 浅浅的谈一下ThreadLocalInsecureRandom
- c——顺序结构
- 完爆面试官,一线互联网企业高级Android工程师面试题大全
- 成功入职百度月薪35K,2022Android开发面试解答
猜你喜欢

UWB ultra wideband positioning technology, real-time centimeter level high-precision positioning application, ultra wideband transmission technology

【obs】QString的UTF-8中文转换到blog打印 UTF-8 char*

95后阿里P7晒出工资单:狠补了这个,真香...

leetcode刷题:二叉树13(相同的树)
![[OBS] qstring's UTF-8 Chinese conversion to blog printing UTF-8 char*](/img/cc/172684664a9115943d45b0646ef110.png)
[OBS] qstring's UTF-8 Chinese conversion to blog printing UTF-8 char*

力扣 729. 我的日程安排表 I

Interviewer: what is the internal implementation of set data types in redis?

Webuploader file upload drag upload progress monitoring type control upload result monitoring control

Securerandom things | true and false random numbers

Based on vs2017 and cmake GUI configuration, zxing and opencv are used in win10 x64 environment, and simple detection of data matrix code is realized
随机推荐
国信证券在网上开户安全吗?
What are general items
图嵌入Graph embedding学习笔记
城链科技数字化创新战略峰会圆满召开
S7-200smart uses V90 Modbus communication control library to control the specific methods and steps of V90 servo
Analysis of openh264 decoded data flow
Android interview classic, 2022 Android interview written examination summary
Webuploader file upload drag upload progress monitoring type control upload result monitoring control
Is it safe for Guosen Securities to open an account online?
Jvmrandom cannot set seeds | problem tracing | source code tracing
众昂矿业:2022年全球萤石行业市场供给现状分析
Relationship between floating elements and parent and brother boxes
打新债在哪里操作开户是更安全可靠的呢
How to apply smart contracts more wisely in 2022?
挖财钱堂教育靠谱安全吗?
浮动元素与父级、兄弟盒子的关系
id选择器和类选择器的区别
Fundamentals of deep learning convolutional neural network (CNN)
Float.floatToRawIntBits的返回值具体意思,将float转为byte数组
Inventory of the most complete low code / no code platforms in the whole network: Jiandao cloud, partner cloud, Mingdao cloud, Qingliu, xurong cloud, Jijian cloud, treelab, nailing · Yida, Tencent clo