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

Skip to content

Commit 26f2e68

Browse files
authored
Clean-up the argparse docs quick links table (GH-91726)
1 parent 4d2403f commit 26f2e68

File tree

1 file changed

+33
-55
lines changed

1 file changed

+33
-55
lines changed

Doc/library/argparse.rst

Lines changed: 33 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -26,73 +26,51 @@ module also automatically generates help and usage messages and issues errors
2626
when users give the program invalid arguments.
2727

2828

29-
Summary
30-
-------
31-
3229
Core Functionality
33-
^^^^^^^^^^^^^^^^^^
30+
------------------
3431

3532
The :mod:`argparse` module's support for command-line interfaces is built
36-
from the following:
37-
38-
The :class:`argparse.ArgumentParser` creates a new :class:`ArgumentParser`
39-
object. Commonly used arguments include prog_, description_, and
40-
formatter_class_. For example, the user can create an instance of
41-
:class:`ArgumentParser` through the following::
42-
43-
>>> parser = argparse.ArgumentParser(prog='PROG', description='DESC',
44-
... formatter_class=argparse.RawDescriptionHelpFormatter)
45-
46-
The :func:`ArgumentParser.add_argument` is a function that is used
47-
to define how a single command-line argument should be parsed. Commonly used
48-
arguments include `name or flags`_, action_, default_, type_, required_,
49-
and help_. An example of the function :func:`ArgumentParser.add_argument`
50-
is as follows::
51-
52-
>>> parser.add_argument('-v', '--verbose', action='store_true',
53-
... help='Show various debugging information')
33+
around an instance of :class:`argparse.ArgumentParser`. It is a container for
34+
argument specifications and has options that apply the parser as whole::
5435

36+
parser = argparse.ArgumentParser(
37+
prog = 'ProgramName',
38+
description = 'What the program does',
39+
epilog = 'Text at the bottom of help')
5540

56-
Basic Usage of :func:`add_argument`
57-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
41+
The :func:`ArgumentParser.add_argument` function attaches individual argument
42+
specifications to the parser. It supports positional arguments, options that
43+
accept values, and on/off flags::
5844

45+
parser.add_argument('filename') # positional argument
46+
parser.add_argument('-c', '--count') # option that takes value
47+
parser.add_argument('-v', '--verbose',
48+
action='store_true') # on/off flag
5949

60-
**Name or Flags Type**
50+
The :func:`ArgumentParser.parse_args` function runs the parser and puts
51+
the extracted data in a :class:`argparse.Namespace` object::
6152

62-
====================== ===========================
63-
Type Example
64-
====================== ===========================
65-
Positional ``'foo'``
66-
Optional ``'-v'``, ``'--verbose'``
67-
====================== ===========================
53+
args = parser.parse_args()
54+
print(args.filename, args.count, args.verbose)
6855

6956

70-
**Basic Arguments:**
57+
Quick Links for add_argument()
58+
------------------------------
7159

72-
====================== =========================================================== =========================================================================================================================
73-
Name Description Keywords
74-
====================== =========================================================== =========================================================================================================================
75-
action_ Specifies how an argument should be handled ``'store'``, ``'store_const'``, ``'store_true'``, ``'append'``, ``'append_const'``, ``'count'``, ``'help'``, ``'version'``
60+
====================== =========================================================== ==========================================================================================================================
61+
Name Description Values
62+
====================== =========================================================== ==========================================================================================================================
63+
action_ Specify how an argument should be handled ``'store'``, ``'store_const'``, ``'store_true'``, ``'append'``, ``'append_const'``, ``'count'``, ``'help'``, ``'version'``
64+
choices_ Limit values to specific set of choices ``['foo', 'bar']``, ``range(1, 10)``, or an object that supports ``in`` operator
65+
const_ Store a constant value
7666
default_ Default value used when an argument is not provided
77-
type_ Automatically converts an argument to the given type :class:`int`, :class:`float`, :class:`bool`, ``argparse.FileType('w')``, ``callable function``
78-
help_ Help message of an argument
79-
====================== =========================================================== =========================================================================================================================
80-
81-
82-
83-
**Advanced Arguments:**
84-
85-
====================== =========================================================== =======================================================================================================================
86-
Name Description Keywords
87-
====================== =========================================================== =======================================================================================================================
88-
nargs_ Associates a single action with the number of arguments ``N`` (:class:`int`), ``'?'``, ``'*'``, ``'+'``, ``argparse.REMAINDER``
89-
const_ Stores constant values of names or flags
90-
choices_ A container that lists the possible values ``['foo', 'bar']``, ``range(1, 10)``, Any object that supports ``in`` operator
91-
required_ Indicates if an optional argument is required or not ``True``, ``False``
92-
metavar_ An alternative display name for the argument
93-
dest_ Specifies name of attribute to be used in ``parse_args()``
94-
====================== =========================================================== =======================================================================================================================
95-
67+
dest_ Specify the attribute name in result namespace
68+
help_ Help message for an argument
69+
metavar_ Alternate display name for the argument as shown in help
70+
nargs_ Number of times the argument can be used ``N`` (:class:`int`), ``'?'``, ``'*'``, ``'+'``, ``argparse.REMAINDER``
71+
required_ Indicate whether an optional argument is required or not ``True``, ``False``
72+
type_ Automatically convert an argument to the given type :class:`int`, :class:`float`, ``argparse.FileType('w')``, or any callable function
73+
====================== =========================================================== ==========================================================================================================================
9674

9775

9876
Example

0 commit comments

Comments
 (0)