I have this simple script named test1.py.
#!/usr/bin/env python
from argparse import ArgumentParser
def cmdlineparse():
parser = ArgumentParser()
parser.add_argument("-tid", dest="CHEMBL_TARGET_ID", required=True, type=str)
parser.add_argument("-molfile", dest="XTEST_MOLFILE", required=False, type=str)
args=parser.parse_args()
return args
if __name__ == '__main__':
args = cmdlineparse()
print("The given CHEMBL_TARGET_ID is %s" % args.CHEMBL_TARGET_ID)
print("The given XTEST_MOLFILE is %s" % args.XTEST_MOLFILE)
Normally, I execute it like this ./test1.py -tid CHEMBL8868 -molfile ligands.sdf.
What I want to do is to execute it multiple times from within a second script named test2.py. The simplest solution would be to call it using subprocess.call or something equivalent.
subprocess.call("./test1.py -tid CHEMBL8868 -molfile ligands.sdf".split(), shell=True, executable='/bin/bash')
However, I would like to do it in a more elegant way, namely by importing it as a module and passing values to argparse. Could someone please show me how to do this?
parse_args()gets values from listsys.argvbut you can use own listparse_args(my_list)