I'd like to pass an "argument" to argument.
I.e., in the following code:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-a")
print parser.parse_args(['-a', 'hi'])
print parser.parse_args(['-a', '-hi'])
The output is:
Namespace(a='hi')
usage: problem.py [-h] [-a A]
problem.py: error: argument -a: expected one argument
While I'd like it to be:
Namespace(a='hi')
Namespace(a='-hi')
How can I achieve that?
I've seen in the help the section 15.4.4.3. Arguments containing -
, but it seems to support only negative numbers. Also, they suggest passing "--", but it's not good in my use case, but everything after the "--" isn't treated as argument (if I understand correctly).
But I want "-a" to consume only 1 argument, and then continue parsing the other arguments as real arguments.
How can it be done?
EDIT
Adding a space before the argument works:
print parser.parse_args(['-a', ' -hi'])
But is there a way to achieve that, without requiring the user to add spaces?