为什么编译的Python模块,但不是脚本正在运行

发布网友

我来回答

1个回答

热心网友

文件是在导入编译。 这不是一个安全的事情。 这仅仅是如果你将其导入蟒蛇保存输出。 看到这个帖子由Fredrik Lundh开发上Effbot。

>>>import main 
# main.pyc is created 

当运行一个脚本巨蟒将不使用* .pyc文件的文件。 如果你有你想要你的脚本一些其他的原因,预编译可以使用compileall模块。

python -m compileall . 

compileall用法

python -m compileall --help 
option --help not recognized 
usage: python compileall.py [-l] [-f] [-q] [-d destdir] [-x regexp] [directory ...] 
-l: don't recurse down 
-f: force rebuild even if timestamps are up-to-date 
-q: quiet operation 
-d destdir: purported directory name for error messages 
if no directory arguments, -l sys.path is assumed 
-x regexp: skip files matching the regular expression regexp 
the regexp is searched for in the full path of the file 

回答以下问题编辑

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com