Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e0bf91d

Browse files
committed
Some markup and style fixes in argparse docs.
1 parent 9375492 commit e0bf91d

1 file changed

Lines changed: 29 additions & 21 deletions

File tree

Doc/library/argparse.rst

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
:mod:`argparse` -- Parser for command line options, arguments and sub-commands
2-
==============================================================================
1+
:mod:`argparse` --- Parser for command line options, arguments and sub-commands
2+
===============================================================================
33

44
.. module:: argparse
55
:synopsis: Command-line option and argument parsing library.
@@ -14,6 +14,7 @@ will figure out how to parse those out of :data:`sys.argv`. The :mod:`argparse`
1414
module also automatically generates help and usage messages and issues errors
1515
when users give the program invalid arguments.
1616

17+
1718
Example
1819
-------
1920

@@ -64,6 +65,7 @@ If invalid arguments are passed in, it will issue an error::
6465

6566
The following sections walk you through this example.
6667

68+
6769
Creating a parser
6870
^^^^^^^^^^^^^^^^^
6971

@@ -97,6 +99,7 @@ will be a list of one or more ints, and the ``accumulate`` attribute will be
9799
either the :func:`sum` function, if ``--sum`` was specified at the command line,
98100
or the :func:`max` function if it was not.
99101

102+
100103
Parsing arguments
101104
^^^^^^^^^^^^^^^^^
102105

@@ -248,7 +251,6 @@ the help options::
248251
+h, ++help show this help message and exit
249252

250253

251-
252254
prefix_chars
253255
^^^^^^^^^^^^
254256

@@ -295,6 +297,7 @@ equivalent to the expression ``['-f', 'foo', '-f', 'bar']``.
295297
The ``fromfile_prefix_chars=`` argument defaults to ``None``, meaning that
296298
arguments will never be treated as file references.
297299

300+
298301
argument_default
299302
^^^^^^^^^^^^^^^^
300303

@@ -594,6 +597,7 @@ The add_argument() method
594597

595598
The following sections describe how each of these are used.
596599

600+
597601
name or flags
598602
^^^^^^^^^^^^^
599603

@@ -623,6 +627,7 @@ When :meth:`parse_args` is called, optional arguments will be identified by the
623627
usage: PROG [-h] [-f FOO] bar
624628
PROG: error: too few arguments
625629

630+
626631
action
627632
^^^^^^
628633

@@ -767,8 +772,10 @@ values are:
767772
output files::
768773

769774
>>> parser = argparse.ArgumentParser()
770-
>>> parser.add_argument('infile', nargs='?', type=argparse.FileType('r'), default=sys.stdin)
771-
>>> parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'), default=sys.stdout)
775+
>>> parser.add_argument('infile', nargs='?', type=argparse.FileType('r'),
776+
... default=sys.stdin)
777+
>>> parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'),
778+
... default=sys.stdout)
772779
>>> parser.parse_args(['input.txt', 'output.txt'])
773780
Namespace(infile=<open file 'input.txt', mode 'r' at 0x...>, outfile=<open file 'output.txt', mode 'w' at 0x...>)
774781
>>> parser.parse_args([])
@@ -1128,7 +1135,7 @@ behavior::
11281135
The parse_args() method
11291136
-----------------------
11301137

1131-
.. method:: ArgumentParser.parse_args([args], [namespace])
1138+
.. method:: ArgumentParser.parse_args(args=None, namespace=None)
11321139

11331140
Convert argument strings to objects and assign them as attributes of the
11341141
namespace. Return the populated namespace.
@@ -1140,6 +1147,7 @@ The parse_args() method
11401147
By default, the arg strings are taken from :data:`sys.argv`, and a new empty
11411148
:class:`Namespace` object is created for the attributes.
11421149

1150+
11431151
Option value syntax
11441152
^^^^^^^^^^^^^^^^^^^
11451153

@@ -1503,7 +1511,7 @@ FileType objects
15031511
Argument groups
15041512
^^^^^^^^^^^^^^^
15051513

1506-
.. method:: ArgumentParser.add_argument_group([title], [description])
1514+
.. method:: ArgumentParser.add_argument_group(title=None, description=None)
15071515

15081516
By default, :class:`ArgumentParser` groups command-line arguments into
15091517
"positional arguments" and "optional arguments" when displaying help
@@ -1527,7 +1535,7 @@ Argument groups
15271535
:class:`ArgumentParser`. When an argument is added to the group, the parser
15281536
treats it just like a normal argument, but displays the argument in a
15291537
separate group for help messages. The :meth:`add_argument_group` method
1530-
accepts ``title`` and ``description`` arguments which can be used to
1538+
accepts *title* and *description* arguments which can be used to
15311539
customize this display::
15321540

15331541
>>> parser = argparse.ArgumentParser(prog='PROG', add_help=False)
@@ -1555,7 +1563,7 @@ Argument groups
15551563
Mutual exclusion
15561564
^^^^^^^^^^^^^^^^
15571565

1558-
.. method:: add_mutually_exclusive_group([required=False])
1566+
.. method:: add_mutually_exclusive_group(required=False)
15591567

15601568
Create a mutually exclusive group. argparse will make sure that only one of
15611569
the arguments in the mutually exclusive group was present on the command
@@ -1573,7 +1581,7 @@ Mutual exclusion
15731581
usage: PROG [-h] [--foo | --bar]
15741582
PROG: error: argument --bar: not allowed with argument --foo
15751583

1576-
The :meth:`add_mutually_exclusive_group` method also accepts a ``required``
1584+
The :meth:`add_mutually_exclusive_group` method also accepts a *required*
15771585
argument, to indicate that at least one of the mutually exclusive arguments
15781586
is required::
15791587

@@ -1586,7 +1594,7 @@ Mutual exclusion
15861594
PROG: error: one of the arguments --foo --bar is required
15871595

15881596
Note that currently mutually exclusive argument groups do not support the
1589-
``title`` and ``description`` arguments of :meth:`add_argument_group`.
1597+
*title* and *description* arguments of :meth:`add_argument_group`.
15901598

15911599

15921600
Parser defaults
@@ -1637,27 +1645,27 @@ In most typical applications, :meth:`parse_args` will take care of formatting
16371645
and printing any usage or error messages. However, several formatting methods
16381646
are available:
16391647

1640-
.. method:: ArgumentParser.print_usage([file]):
1648+
.. method:: ArgumentParser.print_usage(file=None)
16411649

16421650
Print a brief description of how the :class:`ArgumentParser` should be
1643-
invoked on the command line. If ``file`` is not present, ``sys.stderr`` is
1651+
invoked on the command line. If *file* is ``None``, :data:`sys.stderr` is
16441652
assumed.
16451653

1646-
.. method:: ArgumentParser.print_help([file]):
1654+
.. method:: ArgumentParser.print_help(file=None)
16471655

16481656
Print a help message, including the program usage and information about the
1649-
arguments registered with the :class:`ArgumentParser`. If ``file`` is not
1650-
present, ``sys.stderr`` is assumed.
1657+
arguments registered with the :class:`ArgumentParser`. If *file* is
1658+
``None``, :data:`sys.stderr` is assumed.
16511659

16521660
There are also variants of these methods that simply return a string instead of
16531661
printing it:
16541662

1655-
.. method:: ArgumentParser.format_usage():
1663+
.. method:: ArgumentParser.format_usage()
16561664

16571665
Return a string containing a brief description of how the
16581666
:class:`ArgumentParser` should be invoked on the command line.
16591667

1660-
.. method:: ArgumentParser.format_help():
1668+
.. method:: ArgumentParser.format_help()
16611669

16621670
Return a string containing a help message, including the program usage and
16631671
information about the arguments registered with the :class:`ArgumentParser`.
@@ -1666,7 +1674,7 @@ printing it:
16661674
Partial parsing
16671675
^^^^^^^^^^^^^^^
16681676

1669-
.. method:: ArgumentParser.parse_known_args([args], [namespace])
1677+
.. method:: ArgumentParser.parse_known_args(args=None, namespace=None)
16701678

16711679
Sometimes a script may only parse a few of the command line arguments, passing
16721680
the remaining arguments on to another script or program. In these cases, the
@@ -1689,12 +1697,12 @@ Customizing file parsing
16891697

16901698
.. method:: ArgumentParser.convert_arg_line_to_args(arg_line)
16911699

1692-
Arguments that are read from a file (see the ``fromfile_prefix_chars``
1700+
Arguments that are read from a file (see the *fromfile_prefix_chars*
16931701
keyword argument to the :class:`ArgumentParser` constructor) are read one
16941702
argument per line. :meth:`convert_arg_line_to_args` can be overriden for
16951703
fancier reading.
16961704

1697-
This method takes a single argument ``arg_line`` which is a string read from
1705+
This method takes a single argument *arg_line* which is a string read from
16981706
the argument file. It returns a list of arguments parsed from this string.
16991707
The method is called once per line read from the argument file, in order.
17001708

0 commit comments

Comments
 (0)