提高模块的加载速度
- Python 并非完全是解释性语言,它也存在编译。先将源码文件 *.py 编译为 *.pyc,然后由 Python 的虚拟机执行。相对于 *.py 文件来说,编译为 *.pyc本质上和 *.py 没有太大区别,只是提高了模块的加载速度,并没有提高代码的执行速度。
- *.py:源码文件,由 Python 程序解释。
- *.pyc:源码经编译后生成的二进制字节码(Bytecode)文件。
- 也就是说,运行速度相差无几,加载速度 *.pyc 稍占优势。当然,除此之外,还有一个很大的优点:隐藏源码!

demo python 3.8
conda deactivate
conda create -n python38 python=3.8
pip install uncompyle
conda activate python38
tool.py
def user():
print("tool")
util.py
def puts():
print("util")
main.py
from util import puts
from tool import user
puts()
user()
s = set()
s.add(1)
s.add(2)
print(s)
python main.py
util
tool
{1, 2}
当前路径生成了pycache 文件夹
tree pycache/
__pycache__
├── tool.cpython-38.pyc
└── util.cpython-38.pyc
反编译(uncompyle6 不支持高版本 python)
uncompyle6 pycache/tool.cpython-38.pyc >/tmp/test.py
cat /tmp/test.py
# uncompyle6 version 3.9.0
# Python bytecode version base 3.8.0 (3413)
def user():
print( tool )
okay decompiling pycache/tool.cpython-38.pyc
ref
- https://blog.csdn.net/lixinkuan328/article/details/103358409
- pyc
© 版权声明
文章版权归作者所有,未经允许请勿转载。如内容涉嫌侵权,请在本页底部进入<联系我们>进行举报投诉!
THE END



![在苹果iPhone手机上编写ios越狱插件deb[超简单] - 鹿快](https://img.lukuai.com/blogimg/20251123/23f740f048644a198a64e73eeaa43e60.jpg)













暂无评论内容