mirror of
https://github.com/python/cpython.git
synced 2025-08-15 06:10:47 +00:00
Add missing “::” markup and wrap overlong lines
This commit is contained in:
parent
a4c81b07f8
commit
bb42f5ed7f
1 changed files with 23 additions and 18 deletions
|
@ -124,7 +124,9 @@ command-line arguments from :data:`sys.argv`.
|
||||||
ArgumentParser objects
|
ArgumentParser objects
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
.. class:: ArgumentParser([description], [epilog], [prog], [usage], [add_help], [argument_default], [parents], [prefix_chars], [conflict_handler], [formatter_class])
|
.. class:: ArgumentParser([description], [epilog], [prog], [usage], [add_help], \
|
||||||
|
[argument_default], [parents], [prefix_chars], \
|
||||||
|
[conflict_handler], [formatter_class])
|
||||||
|
|
||||||
Create a new :class:`ArgumentParser` object. Each parameter has its own more
|
Create a new :class:`ArgumentParser` object. Each parameter has its own more
|
||||||
detailed description below, but in short they are:
|
detailed description below, but in short they are:
|
||||||
|
@ -576,7 +578,9 @@ your usage messages.
|
||||||
The add_argument() method
|
The add_argument() method
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
||||||
.. method:: ArgumentParser.add_argument(name or flags..., [action], [nargs], [const], [default], [type], [choices], [required], [help], [metavar], [dest])
|
.. method:: ArgumentParser.add_argument(name or flags..., [action], [nargs], \
|
||||||
|
[const], [default], [type], [choices], [required], \
|
||||||
|
[help], [metavar], [dest])
|
||||||
|
|
||||||
Define how a single command-line argument should be parsed. Each parameter
|
Define how a single command-line argument should be parsed. Each parameter
|
||||||
has its own more detailed description below, but in short they are:
|
has its own more detailed description below, but in short they are:
|
||||||
|
@ -718,7 +722,7 @@ how the command-line arguments should be handled. The supported actions are:
|
||||||
|
|
||||||
* ``'version'`` - This expects a ``version=`` keyword argument in the
|
* ``'version'`` - This expects a ``version=`` keyword argument in the
|
||||||
:meth:`~ArgumentParser.add_argument` call, and prints version information
|
:meth:`~ArgumentParser.add_argument` call, and prints version information
|
||||||
and exits when invoked.
|
and exits when invoked::
|
||||||
|
|
||||||
>>> import argparse
|
>>> import argparse
|
||||||
>>> parser = argparse.ArgumentParser(prog='PROG')
|
>>> parser = argparse.ArgumentParser(prog='PROG')
|
||||||
|
@ -770,8 +774,8 @@ single action to be taken. The ``nargs`` keyword argument associates a
|
||||||
different number of command-line arguments with a single action. The supported
|
different number of command-line arguments with a single action. The supported
|
||||||
values are:
|
values are:
|
||||||
|
|
||||||
* ``N`` (an integer). ``N`` arguments from the command line will be gathered together into a
|
* ``N`` (an integer). ``N`` arguments from the command line will be gathered
|
||||||
list. For example::
|
together into a list. For example::
|
||||||
|
|
||||||
>>> parser = argparse.ArgumentParser()
|
>>> parser = argparse.ArgumentParser()
|
||||||
>>> parser.add_argument('--foo', nargs=2)
|
>>> parser.add_argument('--foo', nargs=2)
|
||||||
|
@ -840,7 +844,7 @@ values are:
|
||||||
|
|
||||||
* ``argparse.REMAINDER``. All the remaining command-line arguments are gathered
|
* ``argparse.REMAINDER``. All the remaining command-line arguments are gathered
|
||||||
into a list. This is commonly useful for command line utilities that dispatch
|
into a list. This is commonly useful for command line utilities that dispatch
|
||||||
to other command line utilities.
|
to other command line utilities::
|
||||||
|
|
||||||
>>> parser = argparse.ArgumentParser(prog='PROG')
|
>>> parser = argparse.ArgumentParser(prog='PROG')
|
||||||
>>> parser.add_argument('--foo')
|
>>> parser.add_argument('--foo')
|
||||||
|
@ -863,7 +867,8 @@ the various :class:`ArgumentParser` actions. The two most common uses of it are
|
||||||
|
|
||||||
* When :meth:`~ArgumentParser.add_argument` is called with
|
* When :meth:`~ArgumentParser.add_argument` is called with
|
||||||
``action='store_const'`` or ``action='append_const'``. These actions add the
|
``action='store_const'`` or ``action='append_const'``. These actions add the
|
||||||
``const`` value to one of the attributes of the object returned by :meth:`~ArgumentParser.parse_args`. See the action_ description for examples.
|
``const`` value to one of the attributes of the object returned by
|
||||||
|
:meth:`~ArgumentParser.parse_args`. See the action_ description for examples.
|
||||||
|
|
||||||
* When :meth:`~ArgumentParser.add_argument` is called with option strings
|
* When :meth:`~ArgumentParser.add_argument` is called with option strings
|
||||||
(like ``-f`` or ``--foo``) and ``nargs='?'``. This creates an optional
|
(like ``-f`` or ``--foo``) and ``nargs='?'``. This creates an optional
|
||||||
|
@ -1539,7 +1544,7 @@ Sub-commands
|
||||||
>>> args.func(args)
|
>>> args.func(args)
|
||||||
((XYZYX))
|
((XYZYX))
|
||||||
|
|
||||||
This way, you can let :meth:`parse_args` does the job of calling the
|
This way, you can let :meth:`parse_args` do the job of calling the
|
||||||
appropriate function after argument parsing is complete. Associating
|
appropriate function after argument parsing is complete. Associating
|
||||||
functions with actions like this is typically the easiest way to handle the
|
functions with actions like this is typically the easiest way to handle the
|
||||||
different actions for each of your subparsers. However, if it is necessary
|
different actions for each of your subparsers. However, if it is necessary
|
||||||
|
@ -1564,21 +1569,21 @@ FileType objects
|
||||||
The :class:`FileType` factory creates objects that can be passed to the type
|
The :class:`FileType` factory creates objects that can be passed to the type
|
||||||
argument of :meth:`ArgumentParser.add_argument`. Arguments that have
|
argument of :meth:`ArgumentParser.add_argument`. Arguments that have
|
||||||
:class:`FileType` objects as their type will open command-line arguments as files
|
:class:`FileType` objects as their type will open command-line arguments as files
|
||||||
with the requested modes and buffer sizes:
|
with the requested modes and buffer sizes::
|
||||||
|
|
||||||
>>> parser = argparse.ArgumentParser()
|
>>> parser = argparse.ArgumentParser()
|
||||||
>>> parser.add_argument('--output', type=argparse.FileType('wb', 0))
|
>>> parser.add_argument('--output', type=argparse.FileType('wb', 0))
|
||||||
>>> parser.parse_args(['--output', 'out'])
|
>>> parser.parse_args(['--output', 'out'])
|
||||||
Namespace(output=<open file 'out', mode 'wb' at 0x...>)
|
Namespace(output=<open file 'out', mode 'wb' at 0x...>)
|
||||||
|
|
||||||
FileType objects understand the pseudo-argument ``'-'`` and automatically
|
FileType objects understand the pseudo-argument ``'-'`` and automatically
|
||||||
convert this into ``sys.stdin`` for readable :class:`FileType` objects and
|
convert this into ``sys.stdin`` for readable :class:`FileType` objects and
|
||||||
``sys.stdout`` for writable :class:`FileType` objects:
|
``sys.stdout`` for writable :class:`FileType` objects::
|
||||||
|
|
||||||
>>> parser = argparse.ArgumentParser()
|
>>> parser = argparse.ArgumentParser()
|
||||||
>>> parser.add_argument('infile', type=argparse.FileType('r'))
|
>>> parser.add_argument('infile', type=argparse.FileType('r'))
|
||||||
>>> parser.parse_args(['-'])
|
>>> parser.parse_args(['-'])
|
||||||
Namespace(infile=<open file '<stdin>', mode 'r' at 0x...>)
|
Namespace(infile=<open file '<stdin>', mode 'r' at 0x...>)
|
||||||
|
|
||||||
|
|
||||||
Argument groups
|
Argument groups
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue