gpt4 book ai didi

python - 如何避免 .pyc 文件?

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

我可以在不生成编译后的 .pyc 文件的情况下运行 python 解释器吗?

最佳答案

来自 "What’s New in Python 2.6 - Interpreter Changes" :

Python can now be prevented fromwriting .pyc or .pyo files bysupplying the -B switch to the Pythoninterpreter, or by setting thePYTHONDONTWRITEBYTECODE environmentvariable before running theinterpreter. This setting is availableto Python programs as thesys.dont_write_bytecode variable, andPython code can change the value tomodify the interpreter’s behaviour.

所以以 python -B prog.py 运行你的程序。

2010-11-27 更新:Python 3.2 通过引入一个特殊的 __pycache__ 子文件夹解决了源文件夹与 .pyc 文件杂乱的问题,请参阅 What's New in Python 3.2 - PYC Repository Directories .

注意:默认行为是生成字节码,并且出于“性能”原因而完成(有关更多信息,请参阅此处的 python2 和查看此处的 python3)。

关于python - 如何避免 .pyc 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/154443/

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