[issue13922] argparse handling multiple "--" in args improperly

Steven Bethard report at bugs.python.org
Sun Mar 18 22:41:39 CET 2012


Steven Bethard <steven.bethard at gmail.com> added the comment:

> It prevents implementing parsers that pass strings on to another 
> sub-parser or command.
...
> wouldn't you use 'parse_known_args' instead of 'parse_args'
> and pass the remaining arguments to the next script

I'll just say again that the recommended way of passing arguments to another command is via nargs=argparse.REMAINDER. (Though you may still need "--" if the first argument in the remainder is a flag shared by your parser, as Warren Turka pointed out.)

> I really want "--" to mean "treat everything else as non-optional 
> arguments"

Yep, and that's what it's intended to mean, and what the documentation says:

"you can insert the pseudo-argument '--' which tells parse_args() that everything after that is a positional argument"
http://docs.python.org/library/argparse.html#arguments-containing

It's therefore a bug if there's a '--' after the first '--', but it's not being treated as a positional argument.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13922>
_______________________________________


More information about the Python-bugs-list mailing list