• 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
191 By default, :class:`ArgumentParser` objects use ``sys.argv[0]`` to determine
198 parser = argparse.ArgumentParser()
222 ``prog=`` argument to :class:`ArgumentParser`::
224 >>> parser = argparse.ArgumentParser(prog='myprogram')
237 >>> parser = argparse.ArgumentParser(prog='myprogram')
250 By default, :class:`ArgumentParser` calculates the usage message from the
253 >>> parser = argparse.ArgumentParser(prog='PROG')
268 >>> parser = argparse.ArgumentParser(prog='PROG', usage='%(prog)s [options]')
288 Most calls to the :class:`ArgumentParser` constructor will use the
294 >>> parser = argparse.ArgumentParser(description='A foo that bars')
312 argument to :class:`ArgumentParser`::
314 >>> parser = argparse.ArgumentParser(
329 argument to :class:`ArgumentParser`.
337 shared arguments and passed to ``parents=`` argument to :class:`ArgumentParser`
338 can be used. The ``parents=`` argument takes a list of :class:`ArgumentParser`
340 these actions to the :class:`ArgumentParser` object being constructed::
342 >>> parent_parser = argparse.ArgumentParser(add_help=False)
345 >>> foo_parser = argparse.ArgumentParser(parents=[parent_parser])
350 >>> bar_parser = argparse.ArgumentParser(parents=[parent_parser])
356 :class:`ArgumentParser` will see two ``-h/--help`` options (one in the parent
368 :class:`ArgumentParser` objects allow the help formatting to be customized by
379 By default, :class:`ArgumentParser` objects line-wrap the description_ and
382 >>> parser = argparse.ArgumentParser(
406 >>> parser = argparse.ArgumentParser(
436 >>> parser = argparse.ArgumentParser(
455 >>> parser = argparse.ArgumentParser(
478 to the ArgumentParser constructor::
480 >>> parser = argparse.ArgumentParser(prog='PROG', prefix_chars='-+')
497 :class:`ArgumentParser` constructor, then arguments that start with any of the
503 >>> parser = argparse.ArgumentParser(fromfile_prefix_chars='@')
509 :meth:`~ArgumentParser.convert_arg_line_to_args`) and are treated as if they
522 :meth:`~ArgumentParser.add_argument` or by calling the
523 :meth:`~ArgumentParser.set_defaults` methods with a specific set of name-value
526 ``argument_default=`` keyword argument to :class:`ArgumentParser`. For example,
527 to globally suppress attribute creation on :meth:`~ArgumentParser.parse_args`
530 >>> parser = argparse.ArgumentParser(argument_default=argparse.SUPPRESS)
544 :meth:`~ArgumentParser.parse_args` method of an :class:`ArgumentParser`,
549 >>> parser = argparse.ArgumentParser(prog='PROG', allow_abbrev=False)
562 :class:`ArgumentParser` objects do not allow two actions with the same option
563 string. By default, :class:`ArgumentParser` objects raise an exception if an
567 >>> parser = argparse.ArgumentParser(prog='PROG')
577 :class:`ArgumentParser`::
579 >>> parser = argparse.ArgumentParser(prog='PROG', conflict_handler='resolve')
590 Note that :class:`ArgumentParser` objects only remove an action if all of its
599 By default, ArgumentParser objects add an option which simply displays
604 parser = argparse.ArgumentParser()
608 If ``-h`` or ``--help`` is supplied at the command line, the ArgumentParser
622 :class:`ArgumentParser`::
624 >>> parser = argparse.ArgumentParser(prog='PROG', add_help=False)
638 >>> parser = argparse.ArgumentParser(prog='PROG', prefix_chars='+/')
649 .. method:: ArgumentParser.add_argument(name or flags..., [action], [nargs], \
689 The :meth:`~ArgumentParser.add_argument` method must know whether an optional
692 :meth:`~ArgumentParser.add_argument` must therefore be either a series of
702 When :meth:`~ArgumentParser.parse_args` is called, optional arguments will be
706 >>> parser = argparse.ArgumentParser(prog='PROG')
721 :class:`ArgumentParser` objects associate command-line arguments with actions. These
724 :meth:`~ArgumentParser.parse_args`. The ``action`` keyword argument specifies
730 >>> parser = argparse.ArgumentParser()
739 >>> parser = argparse.ArgumentParser()
749 >>> parser = argparse.ArgumentParser()
760 >>> parser = argparse.ArgumentParser()
771 >>> parser = argparse.ArgumentParser()
780 >>> parser = argparse.ArgumentParser()
787 added to the parser. See :class:`ArgumentParser` for details of how the
791 :meth:`~ArgumentParser.add_argument` call, and prints version information
795 >>> parser = argparse.ArgumentParser(prog='PROG')
816 >>> parser = argparse.ArgumentParser()
830 ArgumentParser objects usually associate a single command-line argument with a
838 >>> parser = argparse.ArgumentParser()
856 >>> parser = argparse.ArgumentParser()
869 >>> parser = argparse.ArgumentParser()
888 >>> parser = argparse.ArgumentParser()
901 >>> parser = argparse.ArgumentParser(prog='PROG')
915 >>> parser = argparse.ArgumentParser(prog='PROG')
930 The ``const`` argument of :meth:`~ArgumentParser.add_argument` is used to hold
932 the various :class:`ArgumentParser` actions. The two most common uses of it are:
934 * When :meth:`~ArgumentParser.add_argument` is called with
937 :meth:`~ArgumentParser.parse_args`. See the action_ description for examples.
939 * When :meth:`~ArgumentParser.add_argument` is called with option strings
955 :meth:`~ArgumentParser.add_argument`, whose value defaults to ``None``,
960 >>> parser = argparse.ArgumentParser()
972 >>> parser = argparse.ArgumentParser()
981 >>> parser = argparse.ArgumentParser()
992 >>> parser = argparse.ArgumentParser()
1003 By default, :class:`ArgumentParser` objects read command-line arguments in as simple
1006 ``type`` keyword argument of :meth:`~ArgumentParser.add_argument` allows any
1010 >>> parser = argparse.ArgumentParser()
1024 >>> parser = argparse.ArgumentParser()
1040 >>> parser = argparse.ArgumentParser(prog='PROG')
1051 >>> parser = argparse.ArgumentParser(prog='PROG')
1067 argument to :meth:`~ArgumentParser.add_argument`. When the command line is
1071 >>> parser = argparse.ArgumentParser(prog='game.py')
1084 >>> parser = argparse.ArgumentParser(prog='doors.py')
1103 keyword argument to :meth:`~ArgumentParser.add_argument`::
1105 >>> parser = argparse.ArgumentParser()
1114 :meth:`~ArgumentParser.parse_args` will report an error if that option is not
1131 >>> parser = argparse.ArgumentParser(prog='frobble')
1149 :meth:`~ArgumentParser.add_argument`, e.g. ``%(default)s``, ``%(type)s``, etc.::
1151 >>> parser = argparse.ArgumentParser(prog='frobble')
1169 >>> parser = argparse.ArgumentParser(prog='frobble')
1181 When :class:`ArgumentParser` generates help messages, it needs some way to refer
1182 to each expected argument. By default, ArgumentParser objects use the dest_
1190 >>> parser = argparse.ArgumentParser()
1207 >>> parser = argparse.ArgumentParser()
1223 attribute on the :meth:`~ArgumentParser.parse_args` object is still determined
1230 >>> parser = argparse.ArgumentParser(prog='PROG')
1245 Most :class:`ArgumentParser` actions add some value as an attribute of the
1246 object returned by :meth:`~ArgumentParser.parse_args`. The name of this
1248 :meth:`~ArgumentParser.add_argument`. For positional argument actions,
1250 :meth:`~ArgumentParser.add_argument`::
1252 >>> parser = argparse.ArgumentParser()
1258 the option strings. :class:`ArgumentParser` generates the value of ``dest`` by
1266 >>> parser = argparse.ArgumentParser()
1276 >>> parser = argparse.ArgumentParser()
1293 Action objects are used by an ArgumentParser to represent the information
1296 plus any keyword arguments passed to :meth:`ArgumentParser.add_argument`
1307 * ``parser`` - The ArgumentParser object which contains this action.
1310 :meth:`~ArgumentParser.parse_args`. Most actions add an attribute to this
1315 :meth:`~ArgumentParser.add_argument`.
1328 .. method:: ArgumentParser.parse_args(args=None, namespace=None)
1347 The :meth:`~ArgumentParser.parse_args` method supports several ways of
1351 >>> parser = argparse.ArgumentParser(prog='PROG')
1375 >>> parser = argparse.ArgumentParser(prog='PROG')
1386 While parsing the command line, :meth:`~ArgumentParser.parse_args` checks for a
1391 >>> parser = argparse.ArgumentParser(prog='PROG')
1414 The :meth:`~ArgumentParser.parse_args` method attempts to give errors whenever
1418 The :meth:`~ArgumentParser.parse_args` method is cautious here: positional
1422 >>> parser = argparse.ArgumentParser(prog='PROG')
1434 >>> parser = argparse.ArgumentParser(prog='PROG')
1454 :meth:`~ArgumentParser.parse_args` that everything after that is a positional
1465 The :meth:`~ArgumentParser.parse_args` method :ref:`by default <allow_abbrev>`
1469 >>> parser = argparse.ArgumentParser(prog='PROG')
1488 Sometimes it may be useful to have an ArgumentParser parse arguments other than those
1490 :meth:`~ArgumentParser.parse_args`. This is useful for testing at the
1493 >>> parser = argparse.ArgumentParser()
1512 Simple class used by default by :meth:`~ArgumentParser.parse_args` to create
1519 >>> parser = argparse.ArgumentParser()
1525 It may also be useful to have an :class:`ArgumentParser` assign attributes to an
1533 >>> parser = argparse.ArgumentParser()
1546 .. method:: ArgumentParser.add_subparsers([title], [description], [prog], \
1556 :class:`ArgumentParser` supports the creation of such sub-commands with the
1559 has a single method, :meth:`~ArgumentParser.add_parser`, which takes a
1560 command name and any :class:`ArgumentParser` constructor arguments, and
1561 returns an :class:`ArgumentParser` object that can be modified as usual.
1577 default the class of the current parser (e.g. ArgumentParser)
1596 >>> parser = argparse.ArgumentParser(prog='PROG')
1661 >>> parser = argparse.ArgumentParser()
1682 >>> parser = argparse.ArgumentParser()
1702 >>> parser = argparse.ArgumentParser()
1733 >>> parser = argparse.ArgumentParser()
1749 argument of :meth:`ArgumentParser.add_argument`. Arguments that have
1754 >>> parser = argparse.ArgumentParser()
1764 >>> parser = argparse.ArgumentParser()
1776 .. method:: ArgumentParser.add_argument_group(title=None, description=None)
1778 By default, :class:`ArgumentParser` groups command-line arguments into
1784 >>> parser = argparse.ArgumentParser(prog='PROG', add_help=False)
1796 has an :meth:`~ArgumentParser.add_argument` method just like a regular
1797 :class:`ArgumentParser`. When an argument is added to the group, the parser
1803 >>> parser = argparse.ArgumentParser(prog='PROG', add_help=False)
1828 .. method:: ArgumentParser.add_mutually_exclusive_group(required=False)
1834 >>> parser = argparse.ArgumentParser(prog='PROG')
1850 >>> parser = argparse.ArgumentParser(prog='PROG')
1860 :meth:`~ArgumentParser.add_argument_group`.
1866 .. method:: ArgumentParser.set_defaults(**kwargs)
1874 >>> parser = argparse.ArgumentParser()
1882 >>> parser = argparse.ArgumentParser()
1889 parsers. See the :meth:`~ArgumentParser.add_subparsers` method for an
1892 .. method:: ArgumentParser.get_default(dest)
1895 :meth:`~ArgumentParser.add_argument` or by
1896 :meth:`~ArgumentParser.set_defaults`::
1898 >>> parser = argparse.ArgumentParser()
1907 In most typical applications, :meth:`~ArgumentParser.parse_args` will take
1911 .. method:: ArgumentParser.print_usage(file=None)
1913 Print a brief description of how the :class:`ArgumentParser` should be
1917 .. method:: ArgumentParser.print_help(file=None)
1920 arguments registered with the :class:`ArgumentParser`. If *file* is
1926 .. method:: ArgumentParser.format_usage()
1929 :class:`ArgumentParser` should be invoked on the command line.
1931 .. method:: ArgumentParser.format_help()
1934 information about the arguments registered with the :class:`ArgumentParser`.
1940 .. method:: ArgumentParser.parse_known_args(args=None, namespace=None)
1944 :meth:`~ArgumentParser.parse_known_args` method can be useful. It works much like
1945 :meth:`~ArgumentParser.parse_args` except that it does not produce an error when
1951 >>> parser = argparse.ArgumentParser()
1967 .. method:: ArgumentParser.convert_arg_line_to_args(arg_line)
1970 keyword argument to the :class:`ArgumentParser` constructor) are read one
1981 class MyArgumentParser(argparse.ArgumentParser):
1989 .. method:: ArgumentParser.exit(status=0, message=None)
1994 .. method:: ArgumentParser.error(message)
2003 .. method:: ArgumentParser.parse_intermixed_args(args=None, namespace=None)
2004 .. method:: ArgumentParser.parse_known_intermixed_args(args=None, namespace=None)
2007 positional arguments. The :meth:`~ArgumentParser.parse_intermixed_args`
2008 and :meth:`~ArgumentParser.parse_known_intermixed_args` methods
2017 :meth:`~ArgumentParser.parse_known_args` and
2018 :meth:`~ArgumentParser.parse_intermixed_args`: the former returns ``['2',
2022 >>> parser = argparse.ArgumentParser()
2031 :meth:`~ArgumentParser.parse_known_intermixed_args` returns a two item tuple
2033 :meth:`~ArgumentParser.parse_intermixed_args` raises an error if there are any
2063 :meth:`ArgumentParser.add_argument` calls.
2066 parser.parse_args()`` and add additional :meth:`ArgumentParser.add_argument`
2071 by using :meth:`~ArgumentParser.parse_intermixed_args` instead of
2072 :meth:`~ArgumentParser.parse_args`.