如何在一个文件夹中一个接一个地运行多个python文件 [英] How to run multiple python file in a folder one after another

查看:286
本文介绍了如何在一个文件夹中一个接一个地运行多个python文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我大约有20个python文件.

I have around 20 python files.

每次我在终端中依次运行这些文件:

Each time I run these files in the terminal this form one after another :

python a.py
python b.py
python c.py
python d.py
python e.py
python f.py
python g.py
.
.
.

(我在这里提供了通用文件名)

(I have provided general file names here)

此过程需要很多时间.

是否可以通过任何脚本一个接一个地运行这些文件??

Is it possible to run these file together one after another through any script..?

如果可能的话,那怎么..?

If possible, then how..?

请提供代码...

我通过几个站点知道,使用bash脚本,我们可以做到这一点.

I came to know through few sites that, using bash script we can do that..

我不知道如何实现.

如果您可以建议其他任何方法,那也将有所帮助.

If you can suggest any other method, even that would be helpful.

编辑:

我需要使用鼻子测试为每个文件生成报告.

And I need to generate report for each file using nosetests.

我的鼻子测试面临的问题是,它创建了一个名称为results.html的HTML文件.

The problem I am facing with nosetests is that, it creates an HTML file with the name results.html.

每次创建报告时,最新的HTML文件都会替换旧的HTML文件.因为名称相同.

Each time the report is created, the latest HTML file replaces the old HTML file. Beacuse the names are same.

所以我现在正在做的是,每当我运行python文件的鼻子测试时都会重命名报告.运行第二个文件的鼻子测试,生成报告,并将其重命名..它继续...

So what I am doing now is, renaming the report each time i run the nosetests for a python file. Run the nosetests for second file, report gets generated, and rename it.. it goes on...

如果有人可以告诉我如何克服这个问题,那将是有帮助的.

If somebody could tell me how I can overcome this, It would be helpful..

我正在使用Ubuntu 14.04

I am working on Ubuntu 14.04

推荐答案

要动态运行给定文件夹YOUR_FOLDER中的所有python脚本,可以运行以下bash脚本:

To run dynamically all the python scripts in a given folder YOUR_FOLDER, you could run bash script like:

#!/bin/bash

for py_file in $(find $YOUR_FOLDER -name *.py)
do
    python $py_file
done

这篇关于如何在一个文件夹中一个接一个地运行多个python文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆