New submission from Jurko Gospodnetić: If you have an optional nargs=argparse.REMAINDER argument defined then, if specified, its value should contain all the remaining command-line content. However, it seems that value does not include later '--' arguments.
For example, the following works as expected: import argparse parser = argparse.ArgumentParser(prog="PROG") parser.add_argument("--args", nargs=argparse.REMAINDER) args = parser.parse_args("--args cmd --arg1 XX ZZ".split()) assert args.args == ["cmd", "--arg1", "XX", "ZZ"] But the following fails with 'PROG: error: unrecognized arguments: -- ZZ': import argparse parser = argparse.ArgumentParser(prog="PROG") parser.add_argument("--args", nargs=argparse.REMAINDER) args = parser.parse_args("--args cmd --arg1 XX -- ZZ".split()) assert args.args == ["cmd", "--arg1", "XX", "--", "ZZ"] Note that the same code works as expected when using a positional nargs=argparse.REMAINDER arguments: import argparse parser = argparse.ArgumentParser(prog="PROG") parser.add_argument("args", nargs=argparse.REMAINDER) args = parser.parse_args("args cmd --arg1 XX ZZ".split()) assert args.args == ["cmd", "--arg1", "XX", "ZZ"] args = parser.parse_args("args cmd --arg1 XX -- ZZ".split()) assert args.args == ["cmd", "--arg1", "XX", "--", "ZZ"] But that, of course, does not allow us to have the args value start with something like "--blah" that looks like an optional argument. Hope this helps. Best regards, Jurko Gospodnetić ---------- components: Library (Lib) messages: 225484 nosy: Jurko.Gospodnetić priority: normal severity: normal status: open title: argparse not including '--' arguments in previous optional REMAINDER argument type: behavior versions: Python 2.7, Python 3.4 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue22223> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com