1

I have a folder containing several Python files. These files are web automation scripts, so no class or methods.

I would like to have a way to trigger the execution of these files in a specific order. For example by combining them in a separate file that I call from my terminal. Or even better, is it possible to make it a clickable icon in my desktop? I'm on macOS.

I am new to Python so please forgive me if the solution is obvious :p Thanks

NicoBar
  • 555
  • 1
  • 7
  • 16
  • 1
    Does this answer your question? [How to run multiple python file in a folder one after another](https://stackoverflow.com/questions/36836557/how-to-run-multiple-python-file-in-a-folder-one-after-another) – MoonMist Dec 17 '19 at 21:27
  • This might be something you're looking for - https://stackoverflow.com/questions/36836557/how-to-run-multiple-python-file-in-a-folder-one-after-another – Dax Amin Dec 17 '19 at 21:27
  • Thanks I've checked it out but it was a little unclear to me being a newbie – NicoBar Dec 18 '19 at 13:00

1 Answers1

2

You can create a BASH wrapper script that contains all the scripts in a certain order and run the wrapper script. For example, let's call our wrapper script "run_scripts.sh" with the following contents:

#!/bin/bash

python file2.py
python file4.py
python file1.py
python file3.py

Place this file in the same directory as file1, file2, etc. Next, we need to allow the user to run the file by changing the permissions. Execute this command in the terminal to the file:

$ chmod +x run_scripts.sh

Finally, assuming the "run_scripts.sh" file is in the same directory as all the python scripts, it is possible to run the wrapper script in a terminal with the following line:

./run_scripts.sh
Jason K Lai
  • 1,500
  • 5
  • 15
  • Thank you! will try that. I am using Python 3, so I imagine in the wrapper file I should write python3 file2.py right? Also, how can I add a condition that if there's an error in one of the files, it stops the execution of the wrapper? – NicoBar Dec 18 '19 at 12:55