Python版本:3.5
网上找了好多资料都没有直观的写出怎么批量执行,so,整理了一个小程序。最初是为了用Python进行单元测试,同目录下有两个unittest文件,
AllTest.py的目的是批量运行mytest.py、mytest2.py。代码如下:
#批量执行当前文件夹下所有py文件
import os
lst=os.listdir(os.getcwd())
for c in lst:
if os.path.isfile(c) and c.endswith('.py') and c.find("AllTest")==-1: #去掉AllTest.py文件
print(c)
os.system(os.path.join(os.getcwd(),c)) #E:\Python\mytest.py