Lines Matching refs:OptionParser
23 :class:`OptionParser`, populate it with options, and parse the command
29 from optparse import OptionParser
31 parser = OptionParser()
253 First, you need to import the OptionParser class; then, early in the main
254 program, create an OptionParser instance::
256 from optparse import OptionParser
258 parser = OptionParser()
278 The option strings passed to :meth:`OptionParser.add_option` are effectively
457 OptionParser, which you can call at any time before calling :meth:`parse_args`::
476 usage message for your whole program. Here's an OptionParser populated with
480 parser = OptionParser(usage=usage)
563 better help output. An :class:`OptionParser` can contain several option groups,
572 * parser is the :class:`OptionParser` instance the group will be insterted in
578 :class:`OptionParser`) and so the :meth:`add_option` method can be used to add
581 Once all the options are declared, using the :class:`OptionParser` method
660 .. method:: OptionParser.get_option_group(opt_str)
673 argument to OptionParser::
675 parser = OptionParser(usage="%prog [-f] [-q]", version="%prog 1.0")
692 .. method:: OptionParser.print_version(file=None)
699 .. method:: OptionParser.get_version()
712 calls to :func:`OptionParser.add_option`, e.g. invalid option strings, unknown
722 you can call :func:`OptionParser.error` to signal an application-defined error
755 :func:`OptionParser.error` from your application code.
758 you'll need to subclass OptionParser and override its :meth:`~OptionParser.exit`
759 and/or :meth:`~OptionParser.error` methods.
769 from optparse import OptionParser
773 parser = OptionParser(usage)
803 The first step in using :mod:`optparse` is to create an OptionParser instance.
805 .. class:: OptionParser(...)
807 The OptionParser constructor has no required arguments, but a number of
821 class attribute that may be set by OptionParser subclasses), but before
867 is by using :meth:`OptionParser.add_option`, as shown in section
877 the OptionParser constructor, as in::
885 parser = OptionParser(option_list=option_list)
903 :meth:`add_option` method of :class:`OptionParser`.
905 .. method:: OptionParser.add_option(option)
906 OptionParser.add_option(*opt_str, attr=value, ...)
997 :meth:`OptionParser.add_option`. If you pass an option attribute that is not
1029 the command line. See also :meth:`OptionParser.set_defaults`.
1232 OptionParser's constructor and the :attr:`~Option.help` string passed to every
1244 from optparse import OptionParser, SUPPRESS_HELP
1248 parser = OptionParser(add_help_option=False)
1275 Prints the version number supplied to the OptionParser to stdout and exits.
1277 ``print_version()`` method of OptionParser. Generally only relevant if the
1278 ``version`` argument is supplied to the OptionParser constructor. As with
1325 The whole point of creating and populating an OptionParser is to call its
1355 OptionParser's :meth:`error` method with an appropriate end-user error message.
1366 can also poke around your option parser and see what's there. OptionParser
1369 .. method:: OptionParser.disable_interspersed_args()
1389 .. method:: OptionParser.enable_interspersed_args()
1394 .. method:: OptionParser.get_option(opt_str)
1399 .. method:: OptionParser.has_option(opt_str)
1401 Return true if the OptionParser has an option with option string *opt_str*
1404 .. method:: OptionParser.remove_option(opt_str)
1406 If the :class:`OptionParser` has an option corresponding to *opt_str*, that
1409 option belonging to this :class:`OptionParser`, raises :exc:`ValueError`.
1424 (This is particularly true if you've defined your own OptionParser subclass with
1431 parser = OptionParser(..., conflict_handler=handler)
1447 As an example, let's define an :class:`OptionParser` that resolves conflicts
1450 parser = OptionParser(conflict_handler="resolve")
1469 existing OptionParser::
1487 OptionParser instances have several cyclic references. This should not be a
1489 references explicitly by calling :meth:`~OptionParser.destroy` on your
1490 OptionParser once you are done with it. This is particularly useful in
1492 OptionParser.
1500 OptionParser supports several other public methods:
1502 .. method:: OptionParser.set_usage(usage)
1508 .. method:: OptionParser.print_usage(file=None)
1515 .. method:: OptionParser.get_usage()
1520 .. method:: OptionParser.set_defaults(dest=value, ...)
1568 :meth:`OptionParser.add_option` method. Apart from :attr:`~Option.action`, the
1642 is the OptionParser instance driving the whole thing, mainly useful because
1877 by :meth:`OptionParser.parse_args`, or be passed to a callback as the
1882 argument, which is passed as-is to :class:`OptionParser`'s :meth:`error`
1920 OptionParser to use MyOption instead of Option::
1922 parser = OptionParser(option_class=MyOption)
1925 Alternately, you can build your own option list and pass it to OptionParser; if
1927 OptionParser which option class to use::
1930 parser = OptionParser(option_list=option_list)