This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author bobjalex
Recipients bobjalex, martin.panter
Date 2015-05-21.16:46:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <CAKyHfROUQ2kaNM-dQJRDk5=0S8wwQjY4HGHQS=zrjLz43JKgBw@mail.gmail.com>
In-reply-to <1431919756.88.0.268739707848.issue24223@psf.upfronthosting.co.za>
Content
Thanks for the note, Martin. I agree that it's a duplicate. (I had done a
brief search for possible dups, but didn't find that one!)

Bob

On Sun, May 17, 2015 at 8:29 PM, Martin Panter <report@bugs.python.org>
wrote:

>
> Martin Panter added the comment:
>
> I suggest this is a duplicate of Issue 15112. The same problem also
> happens with nargs="*", and that issue apparently has a patch to handle
> both cases.
>
> For the record, this is the resulting error, and a demo that it works if
> the option comes before the positional arguments:
>
> >>> print("test 2:", ap.parse_args(["abc", "--option", "mmm"]))
> usage: [-h] [--option] arg_1 [arg_2]
> : error: unrecognized arguments: mmm
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "/home/proj/python/cpython/Lib/argparse.py", line 1729, in
> parse_args
>     self.error(msg % ' '.join(argv))
>   File "/home/proj/python/cpython/Lib/argparse.py", line 2385, in error
>     self.exit(2, _('%(prog)s: error: %(message)s\n') % args)
>   File "/home/proj/python/cpython/Lib/argparse.py", line 2372, in exit
>     _sys.exit(status)
>   File "/home/pythonstartup.py", line 345, in exit
>     raise SystemExit(code)
> __main__.SystemExit: 2
> >>> ap.parse_args(["--option", "abc", "mmm"])
> Namespace(arg_1='abc', arg_2='mmm', option=True)
>
> ----------
> nosy: +vadmium
> resolution:  -> duplicate
> stage:  -> resolved
> status: open -> closed
> superseder:  -> argparse: nargs='*' positional argument doesn't accept any
> items if preceded by an option and another positional
> title: argparse parsing bug -> argparse parsing (mingling --option and
> optional positional argument)
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue24223>
> _______________________________________
>
History
Date User Action Args
2015-05-21 16:46:53bobjalexsetrecipients: + bobjalex, martin.panter
2015-05-21 16:46:53bobjalexlinkissue24223 messages
2015-05-21 16:46:52bobjalexcreate