gpt4 book ai didi

python - 为什么要编译 Python 代码?

转载 作者:IT老高 更新时间:2023-10-28 12:12:19 26 4
gpt4 key购买 nike

为什么要编译 Python 脚本?您可以直接从 .py 文件运行它们,它工作正常,那么有性能优势还是什么?

我还注意到我的应用程序中的一些文件被编译为 .pyc 而其他文件没有,这是为什么呢?

最佳答案

它被编译成字节码,可以使用得更快、更快。

某些文件没有被编译的原因是你使用 python main.py 调用的主脚本在你每次运行脚本时都会重新编译。所有导入的脚本都将被编译并存储在磁盘上。

Ben Blank 的重要补充:

It's worth noting that while running a compiled script has a faster startup time (as it doesn't need to be compiled), it doesn't run any faster.

关于python - 为什么要编译 Python 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/471191/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com