Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1)

Delta Between Two Patch Sets: Doc/library/argparse.rst

Issue 14191: argparse: nargs='*' doesn't get out-of-order positional parameters
Left Patch Set: Created 7 years, 1 month ago
Right Patch Set: Created 7 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | Lib/argparse.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 :mod:`argparse` --- Parser for command-line options, arguments and sub-commands 1 :mod:`argparse` --- Parser for command-line options, arguments and sub-commands
2 =============================================================================== 2 ===============================================================================
3 3
4 .. module:: argparse 4 .. module:: argparse
5 :synopsis: Command-line option and argument parsing library. 5 :synopsis: Command-line option and argument parsing library.
6 .. moduleauthor:: Steven Bethard <steven.bethard@gmail.com> 6 .. moduleauthor:: Steven Bethard <steven.bethard@gmail.com>
7 .. sectionauthor:: Steven Bethard <steven.bethard@gmail.com> 7 .. sectionauthor:: Steven Bethard <steven.bethard@gmail.com>
8 8
9 .. versionadded:: 3.2 9 .. versionadded:: 3.2
10 10
(...skipping 1847 matching lines...) Expand 10 before | Expand all | Expand 10 after
1858 .. method:: ArgumentParser.exit(status=0, message=None) 1858 .. method:: ArgumentParser.exit(status=0, message=None)
1859 1859
1860 This method terminates the program, exiting with the specified *status* 1860 This method terminates the program, exiting with the specified *status*
1861 and, if given, it prints a *message* before that. 1861 and, if given, it prints a *message* before that.
1862 1862
1863 .. method:: ArgumentParser.error(message) 1863 .. method:: ArgumentParser.error(message)
1864 1864
1865 This method prints a usage message including the *message* to the 1865 This method prints a usage message including the *message* to the
1866 standard error and terminates the program with a status code of 2. 1866 standard error and terminates the program with a status code of 2.
1867 1867
1868 .. _upgrading-optparse-code:
1869
1870 1868
1871 Intermixed parsing 1869 Intermixed parsing
1872 ^^^^^^^^^^^^^^^^^^ 1870 ^^^^^^^^^^^^^^^^^^
1873 1871
1874 .. method:: ArgumentParser.parse_intermixed_args(args=None, namespace=None) 1872 .. method:: ArgumentParser.parse_intermixed_args(args=None, namespace=None)
1875 .. method:: ArgumentParser.parse_known_intermixed_args(args=None, namespace=None ) 1873 .. method:: ArgumentParser.parse_known_intermixed_args(args=None, namespace=None )
1876 1874
1877 Some users expect to freely intermix optional and positional argument strings. F or 1875 Some users expect to freely intermix optional and positional argument strings. F or
1878 example, :mod:`optparse`, by default, allows interspersed argument strings. 1876 example, :mod:`optparse`, by default, allows interspersed argument strings.
1879 GNU :c:func:`getopt` 1877 GNU :c:func:`getopt`
(...skipping 20 matching lines...) Expand all
1900 >>> parser.parse_known_args('cmd1 1 --foo bar 2 3'.split()) 1898 >>> parser.parse_known_args('cmd1 1 --foo bar 2 3'.split())
1901 (Namespace(cmd='cmd1', foo='bar', rest=[1]), ['2', '3']) 1899 (Namespace(cmd='cmd1', foo='bar', rest=[1]), ['2', '3'])
1902 >>> parser.parse_intermixed_args('cmd1 1 --foo bar 2 3'.split()) 1900 >>> parser.parse_intermixed_args('cmd1 1 --foo bar 2 3'.split())
1903 Namespace(cmd='cmd1', foo='bar', rest=[1, 2, 3]) 1901 Namespace(cmd='cmd1', foo='bar', rest=[1, 2, 3])
1904 1902
1905 :meth:`~ArgumentParser.parse_known_intermixed_args` method, returns a 1903 :meth:`~ArgumentParser.parse_known_intermixed_args` method, returns a
1906 two item tuple containing the populated namespace and the list of 1904 two item tuple containing the populated namespace and the list of
1907 remaining argument strings. :meth:`~ArgumentParser.parse_intermixed_args` 1905 remaining argument strings. :meth:`~ArgumentParser.parse_intermixed_args`
1908 raises an error if there are any remaining unparsed argument strings. 1906 raises an error if there are any remaining unparsed argument strings.
1909 1907
1908 .. _upgrading-optparse-code:
1909
1910 Upgrading optparse code 1910 Upgrading optparse code
1911 ----------------------- 1911 -----------------------
1912 1912
1913 Originally, the :mod:`argparse` module had attempted to maintain compatibility 1913 Originally, the :mod:`argparse` module had attempted to maintain compatibility
1914 with :mod:`optparse`. However, :mod:`optparse` was difficult to extend 1914 with :mod:`optparse`. However, :mod:`optparse` was difficult to extend
1915 transparently, particularly with the changes required to support the new 1915 transparently, particularly with the changes required to support the new
1916 ``nargs=`` specifiers and better usage messages. When most everything in 1916 ``nargs=`` specifiers and better usage messages. When most everything in
1917 :mod:`optparse` had either been copy-pasted over or monkey-patched, it no 1917 :mod:`optparse` had either been copy-pasted over or monkey-patched, it no
1918 longer seemed practical to try to maintain the backwards compatibility. 1918 longer seemed practical to try to maintain the backwards compatibility.
1919 1919
(...skipping 19 matching lines...) Expand all
1939 1939
1940 * Replace strings with implicit arguments such as ``%default`` or ``%prog`` with 1940 * Replace strings with implicit arguments such as ``%default`` or ``%prog`` with
1941 the standard Python syntax to use dictionaries to format strings, that is, 1941 the standard Python syntax to use dictionaries to format strings, that is,
1942 ``%(default)s`` and ``%(prog)s``. 1942 ``%(default)s`` and ``%(prog)s``.
1943 1943
1944 * Replace the OptionParser constructor ``version`` argument with a call to 1944 * Replace the OptionParser constructor ``version`` argument with a call to
1945 ``parser.add_argument('--version', action='version', version='<the version>')` ` 1945 ``parser.add_argument('--version', action='version', version='<the version>')` `
1946 1946
1947 * Use :meth:`~ArgumentParser.parse_intermixed_args` if 1947 * Use :meth:`~ArgumentParser.parse_intermixed_args` if
1948 interspersing switches with command arguments is important. 1948 interspersing switches with command arguments is important.
LEFTRIGHT
« no previous file | Lib/argparse.py » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+