Skip to content

Commit fa6dbb1

Browse files
[3.13] GH-139067: Add example for argparse's append action (GH-131389) (#139069)
GH-139067: Add example for `argparse`'s `append` action (GH-131389) (cherry picked from commit 101fd33) Co-authored-by: Moshe Kaplan <[email protected]>
1 parent 5f84c1d commit fa6dbb1

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Doc/library/argparse.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -687,16 +687,16 @@ how the command-line arguments should be handled. The supplied actions are:
687687
>>> parser.parse_args('--foo --bar'.split())
688688
Namespace(foo=True, bar=False, baz=True)
689689

690-
* ``'append'`` - This stores a list, and appends each argument value to the
691-
list. It is useful to allow an option to be specified multiple times.
692-
If the default value is non-empty, the default elements will be present
693-
in the parsed value for the option, with any values from the
694-
command line appended after those default values. Example usage::
690+
* ``'append'`` - This appends each argument value to a list.
691+
It is useful for allowing an option to be specified multiple times.
692+
If the default value is a non-empty list, the parsed value will start
693+
with the default list's elements and any values from the command line
694+
will be appended after those default values. Example usage::
695695

696696
>>> parser = argparse.ArgumentParser()
697-
>>> parser.add_argument('--foo', action='append')
697+
>>> parser.add_argument('--foo', action='append', default=['0'])
698698
>>> parser.parse_args('--foo 1 --foo 2'.split())
699-
Namespace(foo=['1', '2'])
699+
Namespace(foo=['0', '1', '2'])
700700

701701
* ``'append_const'`` - This stores a list, and appends the value specified by
702702
the const_ keyword argument to the list; note that the const_ keyword

0 commit comments

Comments
 (0)