@@ -690,6 +690,21 @@ how the command-line arguments should be handled. The supplied actions are:
690690 >>> parser.parse_args('--str --int'.split())
691691 Namespace(types=[<class 'str'>, <class 'int'>])
692692
693+ * ``'extend' `` - This stores a list and appends each item from the multi-value
694+ argument list to it.
695+ The ``'extend' `` action is typically used with the nargs _ keyword argument
696+ value ``'+' `` or ``'*' ``.
697+ Note that when nargs _ is ``None `` (the default) or ``'?' ``, each
698+ character of the argument string will be appended to the list.
699+ Example usage::
700+
701+ >>> parser = argparse.ArgumentParser()
702+ >>> parser.add_argument("--foo", action="extend", nargs="+", type=str)
703+ >>> parser.parse_args(["--foo", "f1", "--foo", "f2", "f3", "f4"])
704+ Namespace(foo=['f1', 'f2', 'f3', 'f4'])
705+
706+ .. versionadded :: 3.8
707+
693708* ``'count' `` - This counts the number of times a keyword argument occurs. For
694709 example, this is useful for increasing verbosity levels::
695710
@@ -715,17 +730,6 @@ how the command-line arguments should be handled. The supplied actions are:
715730 >>> parser.parse_args(['--version'])
716731 PROG 2.0
717732
718- * ``'extend' `` - This stores a list, and extends each argument value to the
719- list.
720- Example usage::
721-
722- >>> parser = argparse.ArgumentParser()
723- >>> parser.add_argument("--foo", action="extend", nargs="+", type=str)
724- >>> parser.parse_args(["--foo", "f1", "--foo", "f2", "f3", "f4"])
725- Namespace(foo=['f1', 'f2', 'f3', 'f4'])
726-
727- .. versionadded :: 3.8
728-
729733Only actions that consume command-line arguments (e.g. ``'store' ``,
730734``'append' `` or ``'extend' ``) can be used with positional arguments.
731735
0 commit comments