python - 如何通过编写python脚本将所有py文件编译为文件夹中的pyc文件?

标签 python

我在 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/

相关文章:

python - 使用颜色图作为第四维(x、y、z 的函数)绘制 3D 表面

python - 如何正确删除 Scikit-Learn 的 DPGMM 的冗余组件?

python - 向量化 numpy 索引并应用函数构建矩阵

.net - Python 中的泛型类型转换

python - 如何降低 Pandas 数据框中的所有元素?

python - 在 telebot @bot.message_handler() 中运行,即使它保存在 if 语句中

python - 如何缩短这个 Python 打印表达式?

python - 包含来自多个列表的数据的字典结构

python - 将 python-dotenv 与 pytest 一起使用的最佳方法,或者使用单独配置的 pytest 测试/开发环境的最佳方法

python - TypeError : 'int' object is not subscriptable because of y=int(x[2:4])