I have the following python program:
#!/usr/bin/env python
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('arg', choices=['foo', 'bar', 'baz'], default='foo', nargs='*')
args = parser.parse_args()
print(args)
If I invoke the program like this:
./prog.py
the output is
Namespace(arg='foo')
But if I invoke the program with foo
as an argument:
./prog.py foo
the output is
Namespace(arg=['foo'])
Question
How can I get arg
's default value to become a list
?
I've tried
I've tried setting default=['foo']
but that results in:
prog.py: error: argument arg: invalid choice: ['foo'] (choose from 'foo', 'bar', 'baz')