Is there a way to produce the equivalent of const
(that we can use with nargs='?'
, see reference question here for an example), but for nargs='*'
. Meaning that I would want:
import argparse
argparser = argparse.ArgumentParser()
argparser.add_argument('--option', nargs='*', const=[1, 2, 3])
print(argparser.parse_args())
And then during usage:
my_script.py # Namespace(option=None)
my_script.py --option # Namespace(option=[1, 2, 3])
my_script.py --option 4 5 # Namespace(option=[4, 5])
Currently I get ValueError: nargs must be '?' to supply const