homepage

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.

classification
Title: argparse usage line is wrong
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: argparse optionals with nargs='?', '*' or '+' can't be followed by positionals
View: 9338
Assigned To: Nosy List: anton.barkovsky, chris.jerdonek, slikts
Priority: normal Keywords:

Created on 2012年07月23日 09:48 by slikts, last changed 2022年04月11日 14:57 by admin. This issue is now closed.

Messages (1)
msg166217 - (view) Author: Reinis Ivanovs (slikts) Date: 2012年07月23日 09:48
I set a positional argument and an optional argument that accepts a list:
> parser = argparse.ArgumentParser()
> parser.add_argument('foo')
> parser.add_argument('-bar', nargs='*')
The usage line I get from --help is this:
> $ example.py --help
> usage: example.py [-h] [-bar [BAR [BAR ...]]] foo
Trying to actually follow the usage instructions produces this error:
> $ example.py -bar x y z
> error: too few arguments
Reversing the argument order works however:
> $ example.py z -bar x y
So the usage instructions are clearly wrong.
History
Date User Action Args
2022年04月11日 14:57:33adminsetgithub: 59638
2012年07月23日 16:46:08bethardsetstatus: open -> closed
2012年07月23日 16:46:01bethardsetsuperseder: argparse optionals with nargs='?', '*' or '+' can't be followed by positionals
resolution: duplicate
2012年07月23日 15:27:14chris.jerdoneksetnosy: + chris.jerdonek
2012年07月23日 14:47:09anton.barkovskysetnosy: + anton.barkovsky
2012年07月23日 09:48:37sliktscreate

AltStyle によって変換されたページ (->オリジナル) /