cpython: 35665f6f3674 (original) (raw)
Mercurial > cpython
changeset 74526:35665f6f3674 2.7
Issue #13605: add documentation for nargs=argparse.REMAINDER [#13605]
Sandro Tosi sandro.tosi@gmail.com | |
---|---|
date | Thu, 19 Jan 2012 21:59:34 +0100 |
parents | d01208ba482f |
children | 1b481e76cd16 |
files | Doc/library/argparse.rst |
diffstat | 1 files changed, 11 insertions(+), 0 deletions(-)[+] [-] Doc/library/argparse.rst 11 |
line wrap: on
line diff
--- a/Doc/library/argparse.rst
+++ b/Doc/library/argparse.rst
@@ -838,6 +838,17 @@ values are:
usage: PROG [-h] foo [foo ...]
PROG: error: too few arguments
+* argparse.REMAINDER
. All the remaining command-line arguments
- are gathered into a lits. This is commonly useful for command line
- utilities that dispatch to other command line utilities. +
>>> parser = argparse.ArgumentParser(prog='PROG')[](#l1.11)
>>> parser.add_argument('--foo')[](#l1.12)
>>> parser.add_argument('command')[](#l1.13)
>>> parser.add_argument('args', nargs=argparse.REMAINDER)[](#l1.14)
>>> print parser.parse_args('--foo B XX YY ZZ'.split())[](#l1.15)
Namespace(args=['YY', 'ZZ'], command='XX', foo='B')[](#l1.16)
+
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
will be consumed and a single item (not a list) will be produced.