mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-23378: Add an extend action to argparse (GH-13305)
Add an extend action to argparse https://bugs.python.org/issue23378
This commit is contained in:
parent
d5c120f7eb
commit
aa32a7e111
4 changed files with 26 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue