summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2022-04-20 06:21:54 (GMT)
committerGitHub <noreply@github.com>2022-04-20 06:21:54 (GMT)
commit26f2e688b84b4c41c3b94b81b747f5776d19a52e (patch)
tree963299f6fff7a876ff7b2a9bf03cbfa7002b5662 /Doc
parent4d2403fd5017324515016a8fad8545935a5c81ef (diff)
downloadcpython-26f2e688b84b4c41c3b94b81b747f5776d19a52e.zip
cpython-26f2e688b84b4c41c3b94b81b747f5776d19a52e.tar.gz
cpython-26f2e688b84b4c41c3b94b81b747f5776d19a52e.tar.bz2
Clean-up the argparse docs quick links table (GH-91726)
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/argparse.rst88
1 files changed, 33 insertions, 55 deletions
diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst
index 425409d..7c20637 100644
--- a/Doc/library/argparse.rst
+++ b/Doc/library/argparse.rst
@@ -26,73 +26,51 @@ module also automatically generates help and usage messages and issues errors
when users give the program invalid arguments.
-Summary
--------
-
Core Functionality
-^^^^^^^^^^^^^^^^^^
+------------------
The :mod:`argparse` module's support for command-line interfaces is built
-from the following:
-
-The :class:`argparse.ArgumentParser` creates a new :class:`ArgumentParser`
-object. Commonly used arguments include prog_, description_, and
-formatter_class_. For example, the user can create an instance of
-:class:`ArgumentParser` through the following::
-
- >>> parser = argparse.ArgumentParser(prog='PROG', description='DESC',
- ... formatter_class=argparse.RawDescriptionHelpFormatter)
-
-The :func:`ArgumentParser.add_argument` is a function that is used
-to define how a single command-line argument should be parsed. Commonly used
-arguments include `name or flags`_, action_, default_, type_, required_,
-and help_. An example of the function :func:`ArgumentParser.add_argument`
-is as follows::
-
- >>> parser.add_argument('-v', '--verbose', action='store_true',
- ... help='Show various debugging information')
+around an instance of :class:`argparse.ArgumentParser`. It is a container for
+argument specifications and has options that apply the parser as whole::
+ parser = argparse.ArgumentParser(
+ prog = 'ProgramName',
+ description = 'What the program does',
+ epilog = 'Text at the bottom of help')
-Basic Usage of :func:`add_argument`
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+The :func:`ArgumentParser.add_argument` function attaches individual argument
+specifications to the parser. It supports positional arguments, options that
+accept values, and on/off flags::
+ parser.add_argument('filename') # positional argument
+ parser.add_argument('-c', '--count') # option that takes value
+ parser.add_argument('-v', '--verbose',
+ action='store_true') # on/off flag
-**Name or Flags Type**
+The :func:`ArgumentParser.parse_args` function runs the parser and puts
+the extracted data in a :class:`argparse.Namespace` object::
-====================== ===========================
-Type Example
-====================== ===========================
-Positional ``'foo'``
-Optional ``'-v'``, ``'--verbose'``
-====================== ===========================
+ args = parser.parse_args()
+ print(args.filename, args.count, args.verbose)
-**Basic Arguments:**
+Quick Links for add_argument()
+------------------------------
-====================== =========================================================== =========================================================================================================================
-Name Description Keywords
-====================== =========================================================== =========================================================================================================================
-action_ Specifies how an argument should be handled ``'store'``, ``'store_const'``, ``'store_true'``, ``'append'``, ``'append_const'``, ``'count'``, ``'help'``, ``'version'``
+====================== =========================================================== ==========================================================================================================================
+Name Description Values
+====================== =========================================================== ==========================================================================================================================
+action_ Specify how an argument should be handled ``'store'``, ``'store_const'``, ``'store_true'``, ``'append'``, ``'append_const'``, ``'count'``, ``'help'``, ``'version'``
+choices_ Limit values to specific set of choices ``['foo', 'bar']``, ``range(1, 10)``, or an object that supports ``in`` operator
+const_ Store a constant value
default_ Default value used when an argument is not provided
-type_ Automatically converts an argument to the given type :class:`int`, :class:`float`, :class:`bool`, ``argparse.FileType('w')``, ``callable function``
-help_ Help message of an argument
-====================== =========================================================== =========================================================================================================================
-
-
-
-**Advanced Arguments:**
-
-====================== =========================================================== =======================================================================================================================
-Name Description Keywords
-====================== =========================================================== =======================================================================================================================
-nargs_ Associates a single action with the number of arguments ``N`` (:class:`int`), ``'?'``, ``'*'``, ``'+'``, ``argparse.REMAINDER``
-const_ Stores constant values of names or flags
-choices_ A container that lists the possible values ``['foo', 'bar']``, ``range(1, 10)``, Any object that supports ``in`` operator
-required_ Indicates if an optional argument is required or not ``True``, ``False``
-metavar_ An alternative display name for the argument
-dest_ Specifies name of attribute to be used in ``parse_args()``
-====================== =========================================================== =======================================================================================================================
-
+dest_ Specify the attribute name in result namespace
+help_ Help message for an argument
+metavar_ Alternate display name for the argument as shown in help
+nargs_ Number of times the argument can be used ``N`` (:class:`int`), ``'?'``, ``'*'``, ``'+'``, ``argparse.REMAINDER``
+required_ Indicate whether an optional argument is required or not ``True``, ``False``
+type_ Automatically convert an argument to the given type :class:`int`, :class:`float`, ``argparse.FileType('w')``, or any callable function
+====================== =========================================================== ==========================================================================================================================
Example