I am using argparse to parse several positional arguments as input and then several positional arguments as output. Since the number of arguments in not bounded, I am trying to use -- as a separator. I have typically been successful with the -- separator using nargs=argparse.REMAINDER, so I tried this:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("input", nargs='+')
parser.add_argument("output", nargs=argparse.REMAINDER)
args = parser.parse_args("input1 input2 -- output1 outpu2".split())
print(args)
However, all arguments are put into input and I get this output:
Namespace(input=['input1', 'input2', 'output1', 'outpu2'], output=[])
The -- is correctly consumed but it does not act as separator.
Is there a way to achieve this using argparse?