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!
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])
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!
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])