Вы можете использовать либо nargs='+'
, либо nargs='*'
.
Они соберут аргументы в список.
import argparse
the_parser = argparse.ArgumentParser()
the_parser.add_argument('--input_files',nargs='+')
args = the_parser.parse_args()
Если вы хотите позвонить из другого скрипта, используя subprocess
, вы можете сделать:
import subprocess
the_files = ['to_merge_1.txt', 'to_merge_2.txt']
cmdlnargs = ['python','argparse_example.py','--input_files']
cmdlnargs.extend(the_files)
subp = subprocess.Popen(cmdlnargs,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.STDOUT)
stdout, stderr = subp.communicate()
print stdout