Is there a way to have an argparse.ArgumentParser not raise an exception upon reading an unknown option, but rather put all the unknown options with values in a dictionary, and those without a value in a list?

For example, say no arguments were defined in the parser for prog.py, and I pass two arguments:

./prog.py --foo bar --baz

I would like the following:

parsed = parser.parse_args()
vals = parsed.unknown_with_vals
novals = parsed.unknown_without_vals

print(vals)
#{'foo' : 'bar'}
print(novals)
#['baz']

Can this be done?

Edit
Report