python批量运行py 文件

os.system(command)  会执行括号中的命令,如果命令成功执行,这条语句返回0,否则返回1。

例:IDE为PyCharm,当前工程目录下有test1.py,test2.py,test3.py 三个文件,现需顺序运行三个文件。方法如下:

在当前目录下新建一个python文件,命名run_all.py,添加如下代码:

import os
os.system("python ./test1.py")
os.system("python ./test2.py")
os.system("python ./test3.py")
然后运行run_all.py文件,即可依次运行三个test文件。

猜你喜欢

转载自blog.csdn.net/Albert201605/article/details/80359301
今日推荐