Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading