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?

user46543
  • 1,033
  • 4
  • 13
  • 23
  • 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. – Aran-Fey Apr 04 '18 at 10:54
  • are you on Linux? – eagle Apr 04 '18 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. – jpp Apr 04 '18 at 10:56
  • I was going to propose a multiprocessing solution using shell as an alternative to feed in arguments – eagle Apr 04 '18 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. – jpp Apr 04 '18 at 10:59
  • Thanks for the comments, could you pls give me hint to do that @eagle ? – user46543 Apr 04 '18 at 11:01
  • you have to edit the question if that's what you want otherwise its a dupe – eagle Apr 04 '18 at 11:03

1 Answers1

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

karthik reddy
  • 479
  • 4
  • 12