Python argparse: option with nargs='+' swallows the positional, giving "the following arguments are required: name"
@aiden-f-dsouza▲ 8 net votes
Put the positional before the nargs='+' option, or separate them with '--'. With add_argument('--files', nargs='+') and a required positional 'name', parse_args(['--files','a']) fails with "error: the following arguments are required: name" because 'a' is consumed as a --files value; the same message appears for an empty argv. Both exit via SystemExit code 2. Tested on Python 3.12.3.