@@ -42,8 +42,8 @@ on the command-line, for example::
42
42
<yourscript> --file=outfile -q
43
43
44
44
As it parses the command line, :mod: `optparse ` sets attributes of the
45
- ``options `` object returned by :meth: `parse_args ` based on user-supplied
46
- command-line values. When :meth: `parse_args ` returns from parsing this command
45
+ ``options `` object returned by :meth: `~OptionParser. parse_args ` based on user-supplied
46
+ command-line values. When :meth: `~OptionParser. parse_args ` returns from parsing this command
47
47
line, ``options.filename `` will be ``"outfile" `` and ``options.verbose `` will be
48
48
``False ``. :mod: `optparse ` supports both long and short options, allows short
49
49
options to be merged together, and allows options to be associated with their
@@ -285,10 +285,10 @@ program's command line::
285
285
286
286
(options, args) = parser.parse_args()
287
287
288
- (If you like, you can pass a custom argument list to :meth: `parse_args `, but
288
+ (If you like, you can pass a custom argument list to :meth: `~OptionParser. parse_args `, but
289
289
that's rarely necessary: by default it uses ``sys.argv[1:] ``.)
290
290
291
- :meth: `parse_args ` returns two values:
291
+ :meth: `~OptionParser. parse_args ` returns two values:
292
292
293
293
* ``options ``, an object containing values for all of your options---e.g. if
294
294
``--file `` takes a single string argument, then ``options.file `` will be the
@@ -339,7 +339,7 @@ Now let's make up a fake command line and ask :mod:`optparse` to parse it::
339
339
340
340
When :mod: `optparse ` sees the option string ``-f ``, it consumes the next
341
341
argument, ``foo.txt ``, and stores it in ``options.filename ``. So, after this
342
- call to :meth: `parse_args `, ``options.filename `` is ``"foo.txt" ``.
342
+ call to :meth: `~OptionParser. parse_args `, ``options.filename `` is ``"foo.txt" ``.
343
343
344
344
Some other option types supported by :mod: `optparse ` are ``int `` and ``float ``.
345
345
Here's an option that expects an integer argument::
@@ -453,7 +453,8 @@ Again, the default value for ``verbose`` will be ``True``: the last default
453
453
value supplied for any particular destination is the one that counts.
454
454
455
455
A clearer way to specify default values is the :meth: `set_defaults ` method of
456
- OptionParser, which you can call at any time before calling :meth: `parse_args `::
456
+ OptionParser, which you can call at any time before calling
457
+ :meth: `~OptionParser.parse_args `::
457
458
458
459
parser.set_defaults(verbose=True)
459
460
parser.add_option(...)
@@ -1338,35 +1339,37 @@ Parsing arguments
1338
1339
^^^^^^^^^^^^^^^^^
1339
1340
1340
1341
The whole point of creating and populating an OptionParser is to call its
1341
- :meth: `parse_args ` method::
1342
+ :meth: `~OptionParser. parse_args ` method.
1342
1343
1343
- (options, args) = parser .parse_args(args=None, values=None)
1344
+ .. method :: OptionParser .parse_args(args=None, values=None)
1344
1345
1345
- where the input parameters are
1346
+ Parse the command-line options found in * args *.
1346
1347
1347
- ``args ``
1348
- the list of arguments to process (default: ``sys.argv[1:] ``)
1348
+ The input parameters are
1349
1349
1350
- ``values ``
1351
- an :class: `optparse.Values ` object to store option arguments in (default: a
1352
- new instance of :class: `Values `) -- if you give an existing object, the
1353
- option defaults will not be initialized on it
1350
+ ``args ``
1351
+ the list of arguments to process (default: ``sys.argv[1:] ``)
1354
1352
1355
- and the return values are
1353
+ ``values ``
1354
+ an :class: `Values ` object to store option arguments in (default: a
1355
+ new instance of :class: `Values `) -- if you give an existing object, the
1356
+ option defaults will not be initialized on it
1356
1357
1357
- ``options ``
1358
- the same object that was passed in as ``values ``, or the optparse.Values
1359
- instance created by :mod: `optparse `
1358
+ and the return value is a pair ``(options, args) `` where
1360
1359
1361
- ``args ``
1362
- the leftover positional arguments after all options have been processed
1360
+ ``options ``
1361
+ the same object that was passed in as *values *, or the ``optparse.Values ``
1362
+ instance created by :mod: `optparse `
1363
+
1364
+ ``args ``
1365
+ the leftover positional arguments after all options have been processed
1363
1366
1364
1367
The most common usage is to supply neither keyword argument. If you supply
1365
1368
``values ``, it will be modified with repeated :func: `setattr ` calls (roughly one
1366
1369
for every option argument stored to an option destination) and returned by
1367
- :meth: `parse_args `.
1370
+ :meth: `~OptionParser. parse_args `.
1368
1371
1369
- If :meth: `parse_args ` encounters any errors in the argument list, it calls the
1372
+ If :meth: `~OptionParser. parse_args ` encounters any errors in the argument list, it calls the
1370
1373
OptionParser's :meth: `error ` method with an appropriate end-user error message.
1371
1374
This ultimately terminates your process with an exit status of 2 (the
1372
1375
traditional Unix exit status for command-line errors).
@@ -1661,7 +1664,7 @@ where
1661
1664
the current list of leftover arguments, ie. arguments that have been
1662
1665
consumed but are neither options nor option arguments. Feel free to modify
1663
1666
``parser.largs ``, e.g. by adding more arguments to it. (This list will
1664
- become ``args ``, the second return value of :meth: `parse_args `.)
1667
+ become ``args ``, the second return value of :meth: `~OptionParser. parse_args `.)
1665
1668
1666
1669
``parser.rargs ``
1667
1670
the current list of remaining arguments, ie. with ``opt_str `` and
0 commit comments