• Home
  • Raw
  • Download

Lines Matching refs:ArgumentParser

37    parser = argparse.ArgumentParser(description='Process some integers.')
90 :class:`ArgumentParser` object::
92 >>> parser = argparse.ArgumentParser(description='Process some integers.')
94 The :class:`ArgumentParser` object will hold all the information necessary to
101 Filling an :class:`ArgumentParser` with information about program arguments is
102 done by making calls to the :meth:`~ArgumentParser.add_argument` method.
103 Generally, these calls tell the :class:`ArgumentParser` how to take the strings
105 used when :meth:`~ArgumentParser.parse_args` is called. For example::
113 Later, calling :meth:`~ArgumentParser.parse_args` will return an object with
123 :class:`ArgumentParser` parses arguments through the
124 :meth:`~ArgumentParser.parse_args` method. This will inspect the command line,
132 In a script, :meth:`~ArgumentParser.parse_args` will typically be called with no
133 arguments, and the :class:`ArgumentParser` will automatically determine the
137 ArgumentParser objects
140 .. class:: ArgumentParser(prog=None, usage=None, description=None, \
147 Create a new :class:`ArgumentParser` object. All parameters should be passed
160 * parents_ - A list of :class:`ArgumentParser` objects whose arguments should
182 * exit_on_error_ - Determines whether or not ArgumentParser exits with
201 By default, :class:`ArgumentParser` objects use ``sys.argv[0]`` to determine
208 parser = argparse.ArgumentParser()
232 ``prog=`` argument to :class:`ArgumentParser`::
234 >>> parser = argparse.ArgumentParser(prog='myprogram')
247 >>> parser = argparse.ArgumentParser(prog='myprogram')
260 By default, :class:`ArgumentParser` calculates the usage message from the
263 >>> parser = argparse.ArgumentParser(prog='PROG')
278 >>> parser = argparse.ArgumentParser(prog='PROG', usage='%(prog)s [options]')
298 Most calls to the :class:`ArgumentParser` constructor will use the
304 >>> parser = argparse.ArgumentParser(description='A foo that bars')
322 argument to :class:`ArgumentParser`::
324 >>> parser = argparse.ArgumentParser(
339 argument to :class:`ArgumentParser`.
347 shared arguments and passed to ``parents=`` argument to :class:`ArgumentParser`
348 can be used. The ``parents=`` argument takes a list of :class:`ArgumentParser`
350 these actions to the :class:`ArgumentParser` object being constructed::
352 >>> parent_parser = argparse.ArgumentParser(add_help=False)
355 >>> foo_parser = argparse.ArgumentParser(parents=[parent_parser])
360 >>> bar_parser = argparse.ArgumentParser(parents=[parent_parser])
366 :class:`ArgumentParser` will see two ``-h/--help`` options (one in the parent
378 :class:`ArgumentParser` objects allow the help formatting to be customized by
389 By default, :class:`ArgumentParser` objects line-wrap the description_ and
392 >>> parser = argparse.ArgumentParser(
416 >>> parser = argparse.ArgumentParser(
446 >>> parser = argparse.ArgumentParser(
465 >>> parser = argparse.ArgumentParser(
488 to the ArgumentParser constructor::
490 >>> parser = argparse.ArgumentParser(prog='PROG', prefix_chars='-+')
507 :class:`ArgumentParser` constructor, then arguments that start with any of the
513 >>> parser = argparse.ArgumentParser(fromfile_prefix_chars='@')
519 :meth:`~ArgumentParser.convert_arg_line_to_args`) and are treated as if they
532 :meth:`~ArgumentParser.add_argument` or by calling the
533 :meth:`~ArgumentParser.set_defaults` methods with a specific set of name-value
536 ``argument_default=`` keyword argument to :class:`ArgumentParser`. For example,
537 to globally suppress attribute creation on :meth:`~ArgumentParser.parse_args`
540 >>> parser = argparse.ArgumentParser(argument_default=argparse.SUPPRESS)
554 :meth:`~ArgumentParser.parse_args` method of an :class:`ArgumentParser`,
559 >>> parser = argparse.ArgumentParser(prog='PROG', allow_abbrev=False)
572 :class:`ArgumentParser` objects do not allow two actions with the same option
573 string. By default, :class:`ArgumentParser` objects raise an exception if an
577 >>> parser = argparse.ArgumentParser(prog='PROG')
587 :class:`ArgumentParser`::
589 >>> parser = argparse.ArgumentParser(prog='PROG', conflict_handler='resolve')
600 Note that :class:`ArgumentParser` objects only remove an action if all of its
609 By default, ArgumentParser objects add an option which simply displays
614 parser = argparse.ArgumentParser()
618 If ``-h`` or ``--help`` is supplied at the command line, the ArgumentParser
632 :class:`ArgumentParser`::
634 >>> parser = argparse.ArgumentParser(prog='PROG', add_help=False)
648 >>> parser = argparse.ArgumentParser(prog='PROG', prefix_chars='+/')
659 Normally, when you pass an invalid argument list to the :meth:`~ArgumentParser.parse_args`
660 method of an :class:`ArgumentParser`, it will exit with error info.
665 >>> parser = argparse.ArgumentParser(exit_on_error=False)
681 .. method:: ArgumentParser.add_argument(name or flags..., [action], [nargs], \
721 The :meth:`~ArgumentParser.add_argument` method must know whether an optional
724 :meth:`~ArgumentParser.add_argument` must therefore be either a series of
734 When :meth:`~ArgumentParser.parse_args` is called, optional arguments will be
738 >>> parser = argparse.ArgumentParser(prog='PROG')
753 :class:`ArgumentParser` objects associate command-line arguments with actions. These
756 :meth:`~ArgumentParser.parse_args`. The ``action`` keyword argument specifies
762 >>> parser = argparse.ArgumentParser()
771 >>> parser = argparse.ArgumentParser()
781 >>> parser = argparse.ArgumentParser()
792 >>> parser = argparse.ArgumentParser()
803 >>> parser = argparse.ArgumentParser()
812 >>> parser = argparse.ArgumentParser()
821 added to the parser. See :class:`ArgumentParser` for details of how the
825 :meth:`~ArgumentParser.add_argument` call, and prints version information
829 >>> parser = argparse.ArgumentParser(prog='PROG')
838 >>> parser = argparse.ArgumentParser()
851 >>> parser = argparse.ArgumentParser()
871 >>> parser = argparse.ArgumentParser()
885 ArgumentParser objects usually associate a single command-line argument with a
893 >>> parser = argparse.ArgumentParser()
911 >>> parser = argparse.ArgumentParser()
924 >>> parser = argparse.ArgumentParser()
943 >>> parser = argparse.ArgumentParser()
956 >>> parser = argparse.ArgumentParser(prog='PROG')
972 The ``const`` argument of :meth:`~ArgumentParser.add_argument` is used to hold
974 the various :class:`ArgumentParser` actions. The two most common uses of it are:
976 * When :meth:`~ArgumentParser.add_argument` is called with
979 :meth:`~ArgumentParser.parse_args`. See the action_ description for examples.
981 * When :meth:`~ArgumentParser.add_argument` is called with option strings
997 :meth:`~ArgumentParser.add_argument`, whose value defaults to ``None``,
1002 >>> parser = argparse.ArgumentParser()
1012 >>> parser = argparse.ArgumentParser()
1022 >>> parser = argparse.ArgumentParser()
1031 >>> parser = argparse.ArgumentParser()
1042 >>> parser = argparse.ArgumentParser()
1053 By default, :class:`ArgumentParser` objects read command-line arguments in as simple
1056 ``type`` keyword argument of :meth:`~ArgumentParser.add_argument` allows any
1060 >>> parser = argparse.ArgumentParser()
1074 >>> parser = argparse.ArgumentParser()
1090 >>> parser = argparse.ArgumentParser(prog='PROG')
1101 >>> parser = argparse.ArgumentParser(prog='PROG')
1117 argument to :meth:`~ArgumentParser.add_argument`. When the command line is
1121 >>> parser = argparse.ArgumentParser(prog='game.py')
1134 >>> parser = argparse.ArgumentParser(prog='doors.py')
1155 keyword argument to :meth:`~ArgumentParser.add_argument`::
1157 >>> parser = argparse.ArgumentParser()
1166 :meth:`~ArgumentParser.parse_args` will report an error if that option is not
1183 >>> parser = argparse.ArgumentParser(prog='frobble')
1201 :meth:`~ArgumentParser.add_argument`, e.g. ``%(default)s``, ``%(type)s``, etc.::
1203 >>> parser = argparse.ArgumentParser(prog='frobble')
1221 >>> parser = argparse.ArgumentParser(prog='frobble')
1233 When :class:`ArgumentParser` generates help messages, it needs some way to refer
1234 to each expected argument. By default, ArgumentParser objects use the dest_
1242 >>> parser = argparse.ArgumentParser()
1259 >>> parser = argparse.ArgumentParser()
1275 attribute on the :meth:`~ArgumentParser.parse_args` object is still determined
1282 >>> parser = argparse.ArgumentParser(prog='PROG')
1297 Most :class:`ArgumentParser` actions add some value as an attribute of the
1298 object returned by :meth:`~ArgumentParser.parse_args`. The name of this
1300 :meth:`~ArgumentParser.add_argument`. For positional argument actions,
1302 :meth:`~ArgumentParser.add_argument`::
1304 >>> parser = argparse.ArgumentParser()
1310 the option strings. :class:`ArgumentParser` generates the value of ``dest`` by
1318 >>> parser = argparse.ArgumentParser()
1328 >>> parser = argparse.ArgumentParser()
1345 Action objects are used by an ArgumentParser to represent the information
1348 plus any keyword arguments passed to :meth:`ArgumentParser.add_argument`
1359 * ``parser`` - The ArgumentParser object which contains this action.
1362 :meth:`~ArgumentParser.parse_args`. Most actions add an attribute to this
1367 :meth:`~ArgumentParser.add_argument`.
1383 .. method:: ArgumentParser.parse_args(args=None, namespace=None)
1402 The :meth:`~ArgumentParser.parse_args` method supports several ways of
1406 >>> parser = argparse.ArgumentParser(prog='PROG')
1430 >>> parser = argparse.ArgumentParser(prog='PROG')
1441 While parsing the command line, :meth:`~ArgumentParser.parse_args` checks for a
1446 >>> parser = argparse.ArgumentParser(prog='PROG')
1469 The :meth:`~ArgumentParser.parse_args` method attempts to give errors whenever
1473 The :meth:`~ArgumentParser.parse_args` method is cautious here: positional
1477 >>> parser = argparse.ArgumentParser(prog='PROG')
1489 >>> parser = argparse.ArgumentParser(prog='PROG')
1509 :meth:`~ArgumentParser.parse_args` that everything after that is a positional
1520 The :meth:`~ArgumentParser.parse_args` method :ref:`by default <allow_abbrev>`
1524 >>> parser = argparse.ArgumentParser(prog='PROG')
1543 Sometimes it may be useful to have an ArgumentParser parse arguments other than those
1545 :meth:`~ArgumentParser.parse_args`. This is useful for testing at the
1548 >>> parser = argparse.ArgumentParser()
1567 Simple class used by default by :meth:`~ArgumentParser.parse_args` to create
1574 >>> parser = argparse.ArgumentParser()
1580 It may also be useful to have an :class:`ArgumentParser` assign attributes to an
1588 >>> parser = argparse.ArgumentParser()
1601 .. method:: ArgumentParser.add_subparsers([title], [description], [prog], \
1611 :class:`ArgumentParser` supports the creation of such sub-commands with the
1614 has a single method, :meth:`~ArgumentParser.add_parser`, which takes a
1615 command name and any :class:`ArgumentParser` constructor arguments, and
1616 returns an :class:`ArgumentParser` object that can be modified as usual.
1632 default the class of the current parser (e.g. ArgumentParser)
1651 >>> parser = argparse.ArgumentParser(prog='PROG')
1716 >>> parser = argparse.ArgumentParser()
1737 >>> parser = argparse.ArgumentParser()
1757 >>> parser = argparse.ArgumentParser()
1788 >>> parser = argparse.ArgumentParser()
1807 argument of :meth:`ArgumentParser.add_argument`. Arguments that have
1812 >>> parser = argparse.ArgumentParser()
1822 >>> parser = argparse.ArgumentParser()
1834 .. method:: ArgumentParser.add_argument_group(title=None, description=None)
1836 By default, :class:`ArgumentParser` groups command-line arguments into
1842 >>> parser = argparse.ArgumentParser(prog='PROG', add_help=False)
1854 has an :meth:`~ArgumentParser.add_argument` method just like a regular
1855 :class:`ArgumentParser`. When an argument is added to the group, the parser
1861 >>> parser = argparse.ArgumentParser(prog='PROG', add_help=False)
1886 .. method:: ArgumentParser.add_mutually_exclusive_group(required=False)
1892 >>> parser = argparse.ArgumentParser(prog='PROG')
1908 >>> parser = argparse.ArgumentParser(prog='PROG')
1918 :meth:`~ArgumentParser.add_argument_group`.
1924 .. method:: ArgumentParser.set_defaults(**kwargs)
1932 >>> parser = argparse.ArgumentParser()
1940 >>> parser = argparse.ArgumentParser()
1947 parsers. See the :meth:`~ArgumentParser.add_subparsers` method for an
1950 .. method:: ArgumentParser.get_default(dest)
1953 :meth:`~ArgumentParser.add_argument` or by
1954 :meth:`~ArgumentParser.set_defaults`::
1956 >>> parser = argparse.ArgumentParser()
1965 In most typical applications, :meth:`~ArgumentParser.parse_args` will take
1969 .. method:: ArgumentParser.print_usage(file=None)
1971 Print a brief description of how the :class:`ArgumentParser` should be
1975 .. method:: ArgumentParser.print_help(file=None)
1978 arguments registered with the :class:`ArgumentParser`. If *file* is
1984 .. method:: ArgumentParser.format_usage()
1987 :class:`ArgumentParser` should be invoked on the command line.
1989 .. method:: ArgumentParser.format_help()
1992 information about the arguments registered with the :class:`ArgumentParser`.
1998 .. method:: ArgumentParser.parse_known_args(args=None, namespace=None)
2002 :meth:`~ArgumentParser.parse_known_args` method can be useful. It works much like
2003 :meth:`~ArgumentParser.parse_args` except that it does not produce an error when
2009 >>> parser = argparse.ArgumentParser()
2025 .. method:: ArgumentParser.convert_arg_line_to_args(arg_line)
2028 keyword argument to the :class:`ArgumentParser` constructor) are read one
2039 class MyArgumentParser(argparse.ArgumentParser):
2047 .. method:: ArgumentParser.exit(status=0, message=None)
2053 class ErrorCatchingArgumentParser(argparse.ArgumentParser):
2059 .. method:: ArgumentParser.error(message)
2068 .. method:: ArgumentParser.parse_intermixed_args(args=None, namespace=None)
2069 .. method:: ArgumentParser.parse_known_intermixed_args(args=None, namespace=None)
2072 positional arguments. The :meth:`~ArgumentParser.parse_intermixed_args`
2073 and :meth:`~ArgumentParser.parse_known_intermixed_args` methods
2082 :meth:`~ArgumentParser.parse_known_args` and
2083 :meth:`~ArgumentParser.parse_intermixed_args`: the former returns ``['2',
2087 >>> parser = argparse.ArgumentParser()
2096 :meth:`~ArgumentParser.parse_known_intermixed_args` returns a two item tuple
2098 :meth:`~ArgumentParser.parse_intermixed_args` raises an error if there are any
2128 :meth:`ArgumentParser.add_argument` calls.
2131 parser.parse_args()`` and add additional :meth:`ArgumentParser.add_argument`
2136 by using :meth:`~ArgumentParser.parse_intermixed_args` instead of
2137 :meth:`~ArgumentParser.parse_args`.