I have a file 'train.py' which takes command line arguments to run. Some arguments are necessary and some are optional
For Example.
.\train.py --counter arg1 --opt optional_arg
Now, I would like to write a new file called 'script.py' which will import this 'train.py' and pass the argumets in that script and execute 'train.py' in 'script.py'
I need to do this as I want to give different set of arguments each time to train.py.
I know we can do this using a shell script. I am curious about how to do it using a python script.
train.py
import optparse
optparser = optparse.OptionParser()
optparser.add_option(
"--counter", default = "",
help = "Counter value"
)
optparser.add_option(
"--opt", default = "",
help = "Optinal parameter"
)
'''Do Something'''
script.py
args = {
'--counter':''
'--opts':''
}
lst = [ 1, 2, 3]
for counter in lst:
'''set command line arguments here in args dictionary'''
args['--counter'] = counter
'''run train.py with args as input dictionary'''