@@ -741,6 +741,21 @@ how the command-line arguments should be handled. The supplied actions are:
741741 >>> parser.parse_args('--str --int'.split())
742742 Namespace(types=[<class 'str'>, <class 'int'>])
743743
744+ * ``'extend' `` - This stores a list, and appends each item from the multi-value
745+ argument list to the list.
746+ The ``'extend' `` action is typically used with the nargs _ keyword argument
747+ value ``'+' `` or ``'*' ``;
748+ note that when nargs _ is ``None `` (by default) or ``'?' ``, separate
749+ characters of the argument string will be appended to the list.
750+ Example usage::
751+
752+ >>> parser = argparse.ArgumentParser()
753+ >>> parser.add_argument("--foo", action="extend", nargs="+", type=str)
754+ >>> parser.parse_args(["--foo", "f1", "--foo", "f2", "f3", "f4"])
755+ Namespace(foo=['f1', 'f2', 'f3', 'f4'])
756+
757+ .. versionadded :: 3.8
758+
744759* ``'count' `` - This counts the number of times a keyword argument occurs. For
745760 example, this is useful for increasing verbosity levels::
746761
@@ -766,17 +781,6 @@ how the command-line arguments should be handled. The supplied actions are:
766781 >>> parser.parse_args(['--version'])
767782 PROG 2.0
768783
769- * ``'extend' `` - This stores a list, and extends each argument value to the
770- list.
771- Example usage::
772-
773- >>> parser = argparse.ArgumentParser()
774- >>> parser.add_argument("--foo", action="extend", nargs="+", type=str)
775- >>> parser.parse_args(["--foo", "f1", "--foo", "f2", "f3", "f4"])
776- Namespace(foo=['f1', 'f2', 'f3', 'f4'])
777-
778- .. versionadded :: 3.8
779-
780784Only actions that consume command-line arguments (e.g. ``'store' ``,
781785``'append' `` or ``'extend' ``) can be used with positional arguments.
782786
0 commit comments