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