summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorBatuhan Taşkaya <47358913+isidentical@users.noreply.github.com>2019-05-21 17:47:42 (GMT)
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-05-21 17:47:42 (GMT)
commitaa32a7e1116f7aaaef9fec453db910e90ab7b101 (patch)
tree2e361b8ada3bdcaac42a8aa0e237baaf814d66c9 /Doc
parentd5c120f7eb6f2a9cdab282a5d588afed307a23df (diff)
downloadcpython-aa32a7e1116f7aaaef9fec453db910e90ab7b101.zip
cpython-aa32a7e1116f7aaaef9fec453db910e90ab7b101.tar.gz
cpython-aa32a7e1116f7aaaef9fec453db910e90ab7b101.tar.bz2
bpo-23378: Add an extend action to argparse (GH-13305)
Add an extend action to argparse https://bugs.python.org/issue23378
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/argparse.rst9
1 files changed, 9 insertions, 0 deletions
diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst
index cef197f..b77a38c 100644
--- a/Doc/library/argparse.rst
+++ b/Doc/library/argparse.rst
@@ -797,6 +797,15 @@ how the command-line arguments should be handled. The supplied actions are:
>>> parser.parse_args(['--version'])
PROG 2.0
+* ``'extend'`` - This stores a list, and extends each argument value to the
+ list.
+ Example usage::
+
+ >>> parser = argparse.ArgumentParser()
+ >>> parser.add_argument("--foo", action="extend", nargs="+", type=str)
+ >>> parser.parse_args(["--foo", "f1", "--foo", "f2", "f3", "f4"])
+ Namespace(foo=['f1', 'f2', 'f3', 'f4'])
+
You may also specify an arbitrary action by passing an Action subclass or
other object that implements the same interface. The recommended way to do
this is to extend :class:`Action`, overriding the ``__call__`` method