在生产环境中,您可能不想泄露自己编写的代码。 如果将py文件编译为pyc文件并在Python上运行这两种类型的文件,则结果相同。 pyc的存在客观上起到了保护代码免受泄露的作用。 下面介绍两种文件的转换方法
pyc—py wget https://bootstrap.pypa.io/get-pip.pypythonget-pip.py本机如果有pip上的这两个步骤就省略pip install uncompyle6将m.pyc
uncompyle6 -o m.py m.pyc使用场景:
发生以下错误时,pyc文件损坏表示可以使用上述方法恢复py文件
runtime error : badmagicnumberin.pycfilepy—pyc安装compileall
pipinstallcompileall2$ catcom.py #!/usr/qpdbks/env python # encoding=utf-8 importcompilealldefcompile _ run (3360 compile all.com pile _ dir ) r '.)。/usr/qpdbks/env python # encoding : utf-8 print (' hello world ' ) [ root @ TSB data1 tmp ] # ls com.py hello.py [ root