argparse
handles a =
joining flag and argument:
parser.add_argument('--argument',help='your help line here')
This will accept either.
'--argument=file.txt'
'--argument file.txt'
The default is to expect one value nargs=None
. If not given the default value is None
.
See
16.4.4.1
For long options (options with names longer than a single character), the option and
value can also be passed as a single command-line argument, using = to separate them:
>>> parser.parse_args('--foo=FOO'.split())
Namespace(foo='FOO', x=None)
Without the --
, the argument is positional
parser.add_argument('argument',help='your help line here')
I assume by 'voluntary' you mean 'optional' (as used in the documentation). But now is required. That is, you'll get an error if you don't provide the filename.