argparse: treat unrecognized options as positional?

Viewed 77

Consider that:

import argparse
p = argparse.ArgumentParser()
p.add_argument('foo', nargs='+')
p.add_argument('--bar')
p.parse_args(['-baz'])

fails with:

error: unrecognized arguments: -baz

Is there anyway to configure ArgumentParser to treat unrecognized options as positional arguments?

In the above example, p.parse_args(["-baz"]) should return Namespace(foo=["-baz"]) instead.

1 Answers
Related