Issue #13605: more meaningful example + fixes

This commit is contained in:
Sandro Tosi 2012-01-19 22:22:35 +01:00
parent 10f047dca8
commit cb21227407
1 changed files with 5 additions and 5 deletions

View File

@ -838,16 +838,16 @@ values are:
usage: PROG [-h] foo [foo ...] usage: PROG [-h] foo [foo ...]
PROG: error: too few arguments PROG: error: too few arguments
* ``argparse.REMAINDER``. All the remaining command-line arguments * ``argparse.REMAINDER``. All the remaining command-line arguments are gathered
are gathered into a lits. This is commonly useful for command line into a list. This is commonly useful for command line utilities that dispatch
utilities that dispatch to other command line utilities. to other command line utilities.
>>> parser = argparse.ArgumentParser(prog='PROG') >>> parser = argparse.ArgumentParser(prog='PROG')
>>> parser.add_argument('--foo') >>> parser.add_argument('--foo')
>>> parser.add_argument('command') >>> parser.add_argument('command')
>>> parser.add_argument('args', nargs=argparse.REMAINDER) >>> parser.add_argument('args', nargs=argparse.REMAINDER)
>>> print parser.parse_args('--foo B XX YY ZZ'.split()) >>> print parser.parse_args('--foo B cmd --arg1 XX ZZ'.split())
Namespace(args=['YY', 'ZZ'], command='XX', foo='B') Namespace(args=['--arg1', 'XX', 'ZZ'], command='cmd', foo='B')
If the ``nargs`` keyword argument is not provided, the number of arguments consumed If the ``nargs`` keyword argument is not provided, the number of arguments consumed
is determined by the action_. Generally this means a single command-line argument is determined by the action_. Generally this means a single command-line argument