2

I am using argparse to pass arguments on the command line, while executing the program. There is one argument that I need to change every time I run the program. I was thinking of storing all the instances of that particular argument in a list and write a program that executes my python program,say test.py taking one instance of that list every time it runs. python test.py --arg1 a1 --arg2 a2

List of instances of arg2 : [a2_1,a2_2,a2_3].
I want to automate the process, such that the following gets executed:

python test.py --arg1 a1 --arg2 a2_1

followed by

python test.py --arg1 a1 --arg2 a2_2

then

python test.py --arg1 a1 --arg2 a2_3

automatically and I dont have to pass the next arguments manually every time one gets executed.
Thanks a lot

vvv
  • 461
  • 1
  • 5
  • 14

1 Answers1

1

If you really want to call your script from "command line", you may do something like that:

import os

args = [a2_1, a2_2, a2_3]
for arg in args:
  os.system("python test.py --arg1 {} --arg2 {}".format(a1, arg))

Make sure that a1 also initialized somewhere in the script.

I recommend you to read this topic though, you might find that useful. Good luck!