@@ -898,6 +898,8 @@ values are:
898
898
usage: PROG [-h] foo [foo ...]
899
899
PROG: error: too few arguments
900
900
901
+ .. _`argparse.REMAINDER` :
902
+
901
903
* ``argparse.REMAINDER ``. All the remaining command-line arguments are gathered
902
904
into a list. This is commonly useful for command line utilities that dispatch
903
905
to other command line utilities::
@@ -1324,8 +1326,11 @@ The parse_args() method
1324
1326
created and how they are assigned. See the documentation for
1325
1327
:meth: `add_argument ` for details.
1326
1328
1327
- By default, the argument strings are taken from :data: `sys.argv `, and a new empty
1328
- :class: `Namespace ` object is created for the attributes.
1329
+ * args _ - List of strings to parse. The default is taken from
1330
+ :data: `sys.argv `.
1331
+
1332
+ * namespace _ - An object to take the attributes. The default is a new empty
1333
+ :class: `Namespace ` object.
1329
1334
1330
1335
1331
1336
Option value syntax
@@ -1467,6 +1472,7 @@ unambiguous (the prefix matches a unique option)::
1467
1472
An error is produced for arguments that could produce more than one options.
1468
1473
This feature can be disabled by setting :ref: `allow_abbrev ` to ``False ``.
1469
1474
1475
+ .. _args :
1470
1476
1471
1477
Beyond ``sys.argv ``
1472
1478
^^^^^^^^^^^^^^^^^^^
@@ -1488,6 +1494,7 @@ interactive prompt::
1488
1494
>>> parser.parse_args(['1', '2', '3', '4', '--sum'])
1489
1495
Namespace(accumulate=<built-in function sum>, integers=[1, 2, 3, 4])
1490
1496
1497
+ .. _namespace :
1491
1498
1492
1499
The Namespace object
1493
1500
^^^^^^^^^^^^^^^^^^^^
@@ -2008,7 +2015,12 @@ A partial upgrade path from :mod:`optparse` to :mod:`argparse`:
2008
2015
* Replace ``(options, args) = parser.parse_args() `` with ``args =
2009
2016
parser.parse_args() `` and add additional :meth: `ArgumentParser.add_argument `
2010
2017
calls for the positional arguments. Keep in mind that what was previously
2011
- called ``options ``, now in :mod: `argparse ` context is called ``args ``.
2018
+ called ``options ``, now in the :mod: `argparse ` context is called ``args ``.
2019
+
2020
+ * Replace :meth: `optparse.OptionParser.disable_interspersed_args `
2021
+ by setting ``nargs `` of a positional argument to `argparse.REMAINDER `_, or
2022
+ use :meth: `~ArgumentParser.parse_known_args ` to collect unparsed argument
2023
+ strings in a separate list.
2012
2024
2013
2025
* Replace callback actions and the ``callback_* `` keyword arguments with
2014
2026
``type `` or ``action `` arguments.
0 commit comments