我在 win 系统上工作,我想知道如何使用可以在 cmd 行中运行的 python 脚本来批量编译 py 文件。 我写了一个简单的 python 代码。
import py_compile, os, glob
dir = 'D:\\FAS\\config'
for f in glob.glob(dir + '\\*.py'):
py_compile.compile(f)
print "Success compile the file: %s" % f
工作不便,无法编译文件夹子文件夹中的文件。希望得到您的帮助。
最佳答案
import compileall
compileall.compile_dir('D:/FAS/config', force=True)
关于python - 如何通过编写python脚本将所有py文件编译为文件夹中的pyc文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13511997/