原意:在cmd命令行下运行命令 python a.py b.py,其中b.py是参数,并且需要使用python2,博主环境变量中的python是python36. 需要用上面的命令行代码批量测试某文件夹下的b.py,得到一群 b.cpp。
代码如下:
import os
os.chdir(r"F:\compiler\PLP\debug_plp\transpiler\test\test_cases")
path = r"F:\compiler\PLP\debug_plp\transpiler\test\test_cases"
files = os.listdir(path)
for file in files:
if file.endswith(".py"):
cmd = "C:\Python27\python.exe F:\compiler\PLP\debug_plp\transpiler\experiment\shedskin- 0.9.4\shedskin\shedskin_init_.py "+file
os.system(cmd)
python 运行cmd命令行
批量转换Python脚本
最新推荐文章于 2024-11-28 22:22:36 发布
本文介绍了一种在Windows环境下,使用Python2批量将特定目录下的Python脚本(.py)转换为另一格式(.cpp)的方法。通过修改当前工作目录并遍历指定路径下的所有文件,当检测到以.py结尾的文件时,利用os模块执行外部命令,调用Python2解释器配合shedskin_init_脚本进行转换。
949

被折叠的 条评论
为什么被折叠?



