[Python-checkins] cpython (3.2): Issue #13605: add documentation for nargs=argparse.REMAINDER

sandro.tosi python-checkins at python.org
Thu Jan 19 22:03:32 CET 2012


http://hg.python.org/cpython/rev/6f3d55f5a31e
changeset:   74527:6f3d55f5a31e
branch:      3.2
parent:      74522:6d663db63705
user:        Sandro Tosi <sandro.tosi at gmail.com>
date:        Thu Jan 19 21:59:55 2012 +0100
summary:
  Issue #13605: add documentation for nargs=argparse.REMAINDER

files:
  Doc/library/argparse.rst |  11 +++++++++++
  1 files changed, 11 insertions(+), 0 deletions(-)


diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst
--- a/Doc/library/argparse.rst
+++ b/Doc/library/argparse.rst
@@ -840,6 +840,17 @@
      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')
+     >>> parser.add_argument('--foo')
+     >>> parser.add_argument('command')
+     >>> parser.add_argument('args', nargs=argparse.REMAINDER)
+     >>> print parser.parse_args('--foo B XX YY ZZ'.split())
+     Namespace(args=['YY', 'ZZ'], command='XX', foo='B')
+
 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.

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list