How to run a python project multiple time on different configurations?

Question:

I have a python project which takes as input a .csv file and some parameters and then give back some results.
Every time I want to try a new coded feature of my code and get the results I have to run the program changing the .csv name and other parameters. So it takes long to change every time this argument, because I have a lot of different input files.

There’s a way to write a program in python which can do this for me?
For example a program that does:

- run "project.py" n times
- first time with "aaa.csv" file as input and parm1=7, then put results in "a_res.csv"
- second time with "bbb.csv" file as input and parm1=4, then put results in "b_res.csv"
- third time with "ccc.csv" file as input and parm1=2, then put results in "c_res.csv"
- fourth time with "ddd.csv" file as input and parm1=6, then put results in "d_res.csv"
- ...

Thanks!

Asked By: Lkmuraz

||

Answers:

yes, make a list of the configurations you want and execute your function in a loop that iterates over this configurations

configurations = [
    ["aaa.csv", 7, "a_res.csv"],
    ["bbb.csv", 4, "b_res.csv"],
    ["ccc.csv", 2, "c_res.csv"],
    ["ddd.csv", 6, "d_res.csv"]]

for c in configurations:
   # assuming your python function accepts 3 parameters:
   # input_file, param1, output_file

   your_python_function(c[0], c[1], c[2])
Answered By: Sembei Norimaki
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.