Commit 543edbda authored by Éric Araujo's avatar Éric Araujo

Don’t quote characters twice.

``code`` markup is enough to mark command-line fragments or to talk
about a character.  ``'c'`` is still used for actual Python string
objects.  I did a similar change in optparse.rst in r86521.

I’ve also ported two minor changes from the 3.3 version of the file
(removing an unnecessary module name in a class directive, adding a
comma).
parent fde92426
...@@ -244,7 +244,7 @@ This can be achieved by passing ``False`` as the ``add_help=`` argument to ...@@ -244,7 +244,7 @@ This can be achieved by passing ``False`` as the ``add_help=`` argument to
--foo FOO foo help --foo FOO foo help
The help option is typically ``-h/--help``. The exception to this is The help option is typically ``-h/--help``. The exception to this is
if the ``prefix_chars=`` is specified and does not include ``'-'``, in if the ``prefix_chars=`` is specified and does not include ``-``, in
which case ``-h`` and ``--help`` are not valid options. In which case ``-h`` and ``--help`` are not valid options. In
this case, the first character in ``prefix_chars`` is used to prefix this case, the first character in ``prefix_chars`` is used to prefix
the help options:: the help options::
...@@ -260,7 +260,7 @@ the help options:: ...@@ -260,7 +260,7 @@ the help options::
prefix_chars prefix_chars
^^^^^^^^^^^^ ^^^^^^^^^^^^
Most command-line options will use ``'-'`` as the prefix, e.g. ``-f/--foo``. Most command-line options will use ``-`` as the prefix, e.g. ``-f/--foo``.
Parsers that need to support different or additional prefix Parsers that need to support different or additional prefix
characters, e.g. for options characters, e.g. for options
like ``+f`` or ``/foo``, may specify them using the ``prefix_chars=`` argument like ``+f`` or ``/foo``, may specify them using the ``prefix_chars=`` argument
...@@ -273,7 +273,7 @@ to the ArgumentParser constructor:: ...@@ -273,7 +273,7 @@ to the ArgumentParser constructor::
Namespace(bar='Y', f='X') Namespace(bar='Y', f='X')
The ``prefix_chars=`` argument defaults to ``'-'``. Supplying a set of The ``prefix_chars=`` argument defaults to ``'-'``. Supplying a set of
characters that does not include ``'-'`` will cause ``-f/--foo`` options to be characters that does not include ``-`` will cause ``-f/--foo`` options to be
disallowed. disallowed.
...@@ -395,7 +395,7 @@ epilog_ texts in command-line help messages:: ...@@ -395,7 +395,7 @@ epilog_ texts in command-line help messages::
likewise for this epilog whose whitespace will be cleaned up and whose words likewise for this epilog whose whitespace will be cleaned up and whose words
will be wrapped across a couple lines will be wrapped across a couple lines
Passing :class:`~argparse.RawDescriptionHelpFormatter` as ``formatter_class=`` Passing :class:`RawDescriptionHelpFormatter` as ``formatter_class=``
indicates that description_ and epilog_ are already correctly formatted and indicates that description_ and epilog_ are already correctly formatted and
should not be line-wrapped:: should not be line-wrapped::
...@@ -421,7 +421,7 @@ should not be line-wrapped:: ...@@ -421,7 +421,7 @@ should not be line-wrapped::
optional arguments: optional arguments:
-h, --help show this help message and exit -h, --help show this help message and exit
:class:`RawTextHelpFormatter` maintains whitespace for all sorts of help text :class:`RawTextHelpFormatter` maintains whitespace for all sorts of help text,
including argument descriptions. including argument descriptions.
The other formatter class available, :class:`ArgumentDefaultsHelpFormatter`, The other formatter class available, :class:`ArgumentDefaultsHelpFormatter`,
...@@ -759,7 +759,7 @@ single action to be taken. The ``nargs`` keyword argument associates a ...@@ -759,7 +759,7 @@ 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 together into a
list. For example:: list. For example::
>>> parser = argparse.ArgumentParser() >>> parser = argparse.ArgumentParser()
...@@ -870,7 +870,7 @@ was not present at the command line:: ...@@ -870,7 +870,7 @@ was not present at the command line::
>>> parser.parse_args(''.split()) >>> parser.parse_args(''.split())
Namespace(foo=42) Namespace(foo=42)
For positional arguments with nargs_ ``='?'`` or ``'*'``, the ``default`` value For positional arguments with nargs_ equal to ``?`` or ``*``, the ``default`` value
is used when no command-line argument was present:: is used when no command-line argument was present::
>>> parser = argparse.ArgumentParser() >>> parser = argparse.ArgumentParser()
...@@ -1133,10 +1133,10 @@ attribute is determined by the ``dest`` keyword argument of ...@@ -1133,10 +1133,10 @@ attribute is determined by the ``dest`` keyword argument of
For optional argument actions, the value of ``dest`` is normally inferred from For optional argument actions, the value of ``dest`` is normally inferred from
the option strings. :class:`ArgumentParser` generates the value of ``dest`` by the option strings. :class:`ArgumentParser` generates the value of ``dest`` by
taking the first long option string and stripping away the initial ``'--'`` taking the first long option string and stripping away the initial ``--``
string. If no long option strings were supplied, ``dest`` will be derived from string. If no long option strings were supplied, ``dest`` will be derived from
the first short option string by stripping the initial ``'-'`` character. Any the first short option string by stripping the initial ``-`` character. Any
internal ``'-'`` characters will be converted to ``'_'`` characters to make sure internal ``-`` characters will be converted to ``_`` characters to make sure
the string is a valid attribute name. The examples below illustrate this the string is a valid attribute name. The examples below illustrate this
behavior:: behavior::
...@@ -1239,15 +1239,15 @@ it exits and prints the error along with a usage message:: ...@@ -1239,15 +1239,15 @@ it exits and prints the error along with a usage message::
PROG: error: extra arguments found: badger PROG: error: extra arguments found: badger
Arguments containing ``"-"`` Arguments containing ``-``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^
The :meth:`~ArgumentParser.parse_args` method attempts to give errors whenever The :meth:`~ArgumentParser.parse_args` method attempts to give errors whenever
the user has clearly made a mistake, but some situations are inherently the user has clearly made a mistake, but some situations are inherently
ambiguous. For example, the command-line argument ``'-1'`` could either be an ambiguous. For example, the command-line argument ``-1`` could either be an
attempt to specify an option or an attempt to provide a positional argument. attempt to specify an option or an attempt to provide a positional argument.
The :meth:`~ArgumentParser.parse_args` method is cautious here: positional The :meth:`~ArgumentParser.parse_args` method is cautious here: positional
arguments may only begin with ``'-'`` if they look like negative numbers and arguments may only begin with ``-`` if they look like negative numbers and
there are no options in the parser that look like negative numbers:: there are no options in the parser that look like negative numbers::
>>> parser = argparse.ArgumentParser(prog='PROG') >>> parser = argparse.ArgumentParser(prog='PROG')
...@@ -1280,7 +1280,7 @@ there are no options in the parser that look like negative numbers:: ...@@ -1280,7 +1280,7 @@ there are no options in the parser that look like negative numbers::
usage: PROG [-h] [-1 ONE] [foo] usage: PROG [-h] [-1 ONE] [foo]
PROG: error: argument -1: expected one argument PROG: error: argument -1: expected one argument
If you have positional arguments that must begin with ``'-'`` and don't look If you have positional arguments that must begin with ``-`` and don't look
like negative numbers, you can insert the pseudo-argument ``'--'`` which tells like negative numbers, you can insert the pseudo-argument ``'--'`` which tells
:meth:`~ArgumentParser.parse_args` that everything after that is a positional :meth:`~ArgumentParser.parse_args` that everything after that is a positional
argument:: argument::
...@@ -1407,8 +1407,8 @@ Sub-commands ...@@ -1407,8 +1407,8 @@ Sub-commands
Note that the object returned by :meth:`parse_args` will only contain Note that the object returned by :meth:`parse_args` will only contain
attributes for the main parser and the subparser that was selected by the attributes for the main parser and the subparser that was selected by the
command line (and not any other subparsers). So in the example above, when command line (and not any other subparsers). So in the example above, when
the ``"a"`` command is specified, only the ``foo`` and ``bar`` attributes are the ``a`` command is specified, only the ``foo`` and ``bar`` attributes are
present, and when the ``"b"`` command is specified, only the ``foo`` and present, and when the ``b`` command is specified, only the ``foo`` and
``baz`` attributes are present. ``baz`` attributes are present.
Similarly, when a help message is requested from a subparser, only the help Similarly, when a help message is requested from a subparser, only the help
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment