0

I have python script called generate_the_result.py. The results can be produced by executing that script with one argument. For example generate_the_result.py my_arg_01

I have a file which the content is the list of arguments of the script.

## my list of arguments
my_arg_01
my_arg_02
my_arg_03
my_arg_04
my_arg_05
.
.
.

I want to execute each argument inside my file above on the generate_the_result.pyscript one by one by looping. How is the best way to do that in python?

there are a lot of arguments inside the file,

a possible solution is read the file, do loop, inside the loop execute subprocess.call("generate_the_result.py [i]") but is this the best way?

7
  • 2
    You can start by reading the arguments from the file... and then starting the other script with those arguments... and then you're done. Really, what's the problem? Reading text from files and starting processes are two easy (and easily googleable) tasks. Commented Apr 4, 2018 at 10:54
  • are you on Linux? Commented Apr 4, 2018 at 10:56
  • I'm closing this with a relevant dup. Just read in your arguments and run your function with each, in a loop, in the script. Commented Apr 4, 2018 at 10:56
  • I was going to propose a multiprocessing solution using shell as an alternative to feed in arguments Commented Apr 4, 2018 at 10:58
  • @eagle, I am not sure the question is about multiprocessing. If user updates the question, then by all means this can be reopened if not a duplicate. Commented Apr 4, 2018 at 10:59

1 Answer 1

0

In my opinion the best way is to give that file path which contains args and write the results into another output file. If file in csv format you can easily iterate aruments.

generate_the_result.py file_name.csv

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.