@@ -854,6 +854,8 @@ values are:
854
854
usage: PROG [-h] foo [foo ...]
855
855
PROG: error: too few arguments
856
856
857
+ .. _`argparse.REMAINDER` :
858
+
857
859
* ``argparse.REMAINDER ``. All the remaining command-line arguments are gathered
858
860
into a list. This is commonly useful for command line utilities that dispatch
859
861
to other command line utilities::
@@ -1275,8 +1277,11 @@ The parse_args() method
1275
1277
created and how they are assigned. See the documentation for
1276
1278
:meth: `add_argument ` for details.
1277
1279
1278
- By default, the argument strings are taken from :data: `sys.argv `, and a new empty
1279
- :class: `Namespace ` object is created for the attributes.
1280
+ * args _ - List of strings to parse. The default is taken from
1281
+ :data: `sys.argv `.
1282
+
1283
+ * namespace _ - An object to take the attributes. The default is a new empty
1284
+ :class: `Namespace ` object.
1280
1285
1281
1286
1282
1287
Option value syntax
@@ -1417,6 +1422,7 @@ a unique option)::
1417
1422
1418
1423
An error is produced for arguments that could produce more than one options.
1419
1424
1425
+ .. _args :
1420
1426
1421
1427
Beyond ``sys.argv ``
1422
1428
^^^^^^^^^^^^^^^^^^^
@@ -1438,6 +1444,7 @@ interactive prompt::
1438
1444
>>> parser.parse_args(['1', '2', '3', '4', '--sum'])
1439
1445
Namespace(accumulate=<built-in function sum>, integers=[1, 2, 3, 4])
1440
1446
1447
+ .. _namespace :
1441
1448
1442
1449
The Namespace object
1443
1450
^^^^^^^^^^^^^^^^^^^^
@@ -1943,7 +1950,12 @@ A partial upgrade path from :mod:`optparse` to :mod:`argparse`:
1943
1950
* Replace ``(options, args) = parser.parse_args() `` with ``args =
1944
1951
parser.parse_args() `` and add additional :meth: `ArgumentParser.add_argument `
1945
1952
calls for the positional arguments. Keep in mind that what was previously
1946
- called ``options ``, now in :mod: `argparse ` context is called ``args ``.
1953
+ called ``options ``, now in the :mod: `argparse ` context is called ``args ``.
1954
+
1955
+ * Replace :meth: `optparse.OptionParser.disable_interspersed_args `
1956
+ by setting ``nargs `` of a positional argument to `argparse.REMAINDER `_, or
1957
+ use :meth: `~ArgumentParser.parse_known_args ` to collect unparsed argument
1958
+ strings in a separate list.
1947
1959
1948
1960
* Replace callback actions and the ``callback_* `` keyword arguments with
1949
1961
``type `` or ``action `` arguments.
0 commit comments