How to run multiple python file in a folder one after another [duplicate]

那年仲夏 提交于 2019-12-04 08:16:05

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
Lucian2k

If you want them ran in parallel there's some useful info in this question How do you run multiple programs in parallel from a bash script?

Your command should look like:

python a.py & python b.py & python c.py ....

If you want them to run one after another then replace the & with ;

python a.py;python b.py;python c.py ...

Hope it helps!

You could use a simple bash script which will execute your commands one after another :

#!/bin/bash
python a.py
python b.py
python c.py
python d.py
python e.py
python f.py
python g.py
.
.
.

If your script is meant to be used on multiple platforms I highly recommand you to precise the python version to execute (python2 or python3).

EDIT : If you need to execute all of the python scripts in your folder, you'd better use a for loop like massiou suggested in his answer.

You can use bash wildcard

create sample file

for f in  test_python{1..9}.py; do echo  "print __file__" > $f; done

File are indexed

ls test*

test_python1.py test_python2.py test_python3.py test_python4.py test_python5.py test_python6.py test_python7.py test_python8.py test_python9.py

Run them in desired order:

for f in  test_python{1..9}.py; do python $f ; done
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!