I want to parse an option with multiple arguments and return a value as a collection of my choice, e.g. a tuple
or an np.array
rather than a list
.
I could simply convert the resulting list after parsing as suggested in this answer,
parser.add_argument('--foo', nargs='*')
options = parser.parse_args('--foo 1 2 3'.split())
# manual casts go here
options.foo = tuple(options.foo)
but this could be cumbersome and error prone esp. if we have many such parameters to convert.
Is it possible to have ArgParser
itself store arguments in a collection other than a list?