@@ -741,6 +741,21 @@ how the command-line arguments should be handled. The supplied actions are:
741
741
>>> parser.parse_args('--str --int'.split())
742
742
Namespace(types=[<class 'str'>, <class 'int'>])
743
743
744
+ * ``'extend' `` - This stores a list and appends each item from the multi-value
745
+ argument list to it.
746
+ The ``'extend' `` action is typically used with thenargs _ keyword argument
747
+ value ``'+' `` or ``'*' ``.
748
+ Note that whennargs _ is ``None `` (the default) or ``'?' ``, each
749
+ character 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
+
744
759
* ``'count' `` - This counts the number of times a keyword argument occurs. For
745
760
example, this is useful for increasing verbosity levels::
746
761
@@ -766,17 +781,6 @@ how the command-line arguments should be handled. The supplied actions are:
766
781
>>> parser.parse_args(['--version'])
767
782
PROG 2.0
768
783
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
-
780
784
Only actions that consume command-line arguments (e.g. ``'store' ``,
781
785
``'append' `` or ``'extend' ``) can be used with positional arguments.
782
786