@@ -633,12 +633,7 @@ them, though most actions simply add an attribute to the object returned by
633633how the command-line arguments should be handled. The supplied actions are:
634634
635635* ``'store' `` - This just stores the argument's value. This is the default
636- action. For example::
637-
638- >>> parser = argparse.ArgumentParser()
639- >>> parser.add_argument('--foo')
640- >>> parser.parse_args('--foo 1'.split())
641- Namespace(foo='1')
636+ action.
642637
643638* ``'store_const' `` - This stores the value specified by the const _ keyword
644639 argument; note that the const _ keyword argument defaults to ``None ``. The
@@ -653,14 +648,7 @@ how the command-line arguments should be handled. The supplied actions are:
653648* ``'store_true' `` and ``'store_false' `` - These are special cases of
654649 ``'store_const' `` used for storing the values ``True `` and ``False ``
655650 respectively. In addition, they create default values of ``False `` and
656- ``True `` respectively. For example::
657-
658- >>> parser = argparse.ArgumentParser()
659- >>> parser.add_argument('--foo', action='store_true')
660- >>> parser.add_argument('--bar', action='store_false')
661- >>> parser.add_argument('--baz', action='store_false')
662- >>> parser.parse_args('--foo --bar'.split())
663- Namespace(foo=True, bar=False, baz=True)
651+ ``True `` respectively.
664652
665653* ``'append' `` - This stores a list, and appends each argument value to the
666654 list. It is useful to allow an option to be specified multiple times.
@@ -1021,28 +1009,11 @@ Some command-line arguments should be selected from a restricted set of values.
10211009These can be handled by passing a sequence object as the *choices * keyword
10221010argument to :meth: `~ArgumentParser.add_argument `. When the command line is
10231011parsed, argument values will be checked, and an error message will be displayed
1024- if the argument was not one of the acceptable values::
1025-
1026- >>> parser = argparse.ArgumentParser(prog='game.py')
1027- >>> parser.add_argument('move', choices=['rock', 'paper', 'scissors'])
1028- >>> parser.parse_args(['rock'])
1029- Namespace(move='rock')
1030- >>> parser.parse_args(['fire'])
1031- usage: game.py [-h] {rock,paper,scissors}
1032- game.py: error: argument move: invalid choice: 'fire' (choose from 'rock',
1033- 'paper', 'scissors')
1012+ if the argument was not one of the acceptable values.
10341013
10351014Note that inclusion in the *choices * sequence is checked after any type _
10361015conversions have been performed, so the type of the objects in the *choices *
1037- sequence should match the type _ specified::
1038-
1039- >>> parser = argparse.ArgumentParser(prog='doors.py')
1040- >>> parser.add_argument('door', type=int, choices=range(1, 4))
1041- >>> print(parser.parse_args(['3']))
1042- Namespace(door=3)
1043- >>> parser.parse_args(['4'])
1044- usage: doors.py [-h] {1,2,3}
1045- doors.py: error: argument door: invalid choice: 4 (choose from 1, 2, 3)
1016+ sequence should match the type _ specified.
10461017
10471018Any sequence can be passed as the *choices * value, so :class: `list ` objects,
10481019:class: `tuple ` objects, and custom sequences are all supported.
@@ -1092,22 +1063,7 @@ help
10921063The ``help `` value is a string containing a brief description of the argument.
10931064When a user requests help (usually by using ``-h `` or ``--help `` at the
10941065command line), these ``help `` descriptions will be displayed with each
1095- argument::
1096-
1097- >>> parser = argparse.ArgumentParser(prog='frobble')
1098- >>> parser.add_argument('--foo', action='store_true',
1099- ... help='foo the bars before frobbling')
1100- >>> parser.add_argument('bar', nargs='+',
1101- ... help='one of the bars to be frobbled')
1102- >>> parser.parse_args(['-h'])
1103- usage: frobble [-h] [--foo] bar [bar ...]
1104-
1105- positional arguments:
1106- bar one of the bars to be frobbled
1107-
1108- options:
1109- -h, --help show this help message and exit
1110- --foo foo the bars before frobbling
1066+ argument.
11111067
11121068The ``help `` strings can include various format specifiers to avoid repetition
11131069of things like the program name or the argument default _. The available
0 commit comments