Lines Matching refs:ArgumentParser
36 parser = argparse.ArgumentParser(description='Process some integers.')
89 :class:`ArgumentParser` object::
91 >>> parser = argparse.ArgumentParser(description='Process some integers.')
93 The :class:`ArgumentParser` object will hold all the information necessary to
100 Filling an :class:`ArgumentParser` with information about program arguments is
101 done by making calls to the :meth:`~ArgumentParser.add_argument` method.
102 Generally, these calls tell the :class:`ArgumentParser` how to take the strings
104 used when :meth:`~ArgumentParser.parse_args` is called. For example::
112 Later, calling :meth:`~ArgumentParser.parse_args` will return an object with
122 :class:`ArgumentParser` parses arguments through the
123 :meth:`~ArgumentParser.parse_args` method. This will inspect the command line,
131 In a script, :meth:`~ArgumentParser.parse_args` will typically be called with no
132 arguments, and the :class:`ArgumentParser` will automatically determine the
136 ArgumentParser objects
139 .. class:: ArgumentParser(prog=None, usage=None, description=None, \
146 Create a new :class:`ArgumentParser` object. All parameters should be passed
159 * parents_ - A list of :class:`ArgumentParser` objects whose arguments should
184 By default, :class:`ArgumentParser` objects use ``sys.argv[0]`` to determine
191 parser = argparse.ArgumentParser()
215 ``prog=`` argument to :class:`ArgumentParser`::
217 >>> parser = argparse.ArgumentParser(prog='myprogram')
230 >>> parser = argparse.ArgumentParser(prog='myprogram')
243 By default, :class:`ArgumentParser` calculates the usage message from the
246 >>> parser = argparse.ArgumentParser(prog='PROG')
261 >>> parser = argparse.ArgumentParser(prog='PROG', usage='%(prog)s [options]')
281 Most calls to the :class:`ArgumentParser` constructor will use the
287 >>> parser = argparse.ArgumentParser(description='A foo that bars')
305 argument to :class:`ArgumentParser`::
307 >>> parser = argparse.ArgumentParser(
322 argument to :class:`ArgumentParser`.
330 shared arguments and passed to ``parents=`` argument to :class:`ArgumentParser`
331 can be used. The ``parents=`` argument takes a list of :class:`ArgumentParser`
333 these actions to the :class:`ArgumentParser` object being constructed::
335 >>> parent_parser = argparse.ArgumentParser(add_help=False)
338 >>> foo_parser = argparse.ArgumentParser(parents=[parent_parser])
343 >>> bar_parser = argparse.ArgumentParser(parents=[parent_parser])
349 :class:`ArgumentParser` will see two ``-h/--help`` options (one in the parent
361 :class:`ArgumentParser` objects allow the help formatting to be customized by
372 By default, :class:`ArgumentParser` objects line-wrap the description_ and
375 >>> parser = argparse.ArgumentParser(
399 >>> parser = argparse.ArgumentParser(
429 >>> parser = argparse.ArgumentParser(
452 to the ArgumentParser constructor::
454 >>> parser = argparse.ArgumentParser(prog='PROG', prefix_chars='-+')
471 :class:`ArgumentParser` constructor, then arguments that start with any of the
477 >>> parser = argparse.ArgumentParser(fromfile_prefix_chars='@')
483 :meth:`~ArgumentParser.convert_arg_line_to_args`) and are treated as if they
496 :meth:`~ArgumentParser.add_argument` or by calling the
497 :meth:`~ArgumentParser.set_defaults` methods with a specific set of name-value
500 ``argument_default=`` keyword argument to :class:`ArgumentParser`. For example,
501 to globally suppress attribute creation on :meth:`~ArgumentParser.parse_args`
504 >>> parser = argparse.ArgumentParser(argument_default=argparse.SUPPRESS)
516 :class:`ArgumentParser` objects do not allow two actions with the same option
517 string. By default, :class:`ArgumentParser` objects raise an exception if an
521 >>> parser = argparse.ArgumentParser(prog='PROG')
531 :class:`ArgumentParser`::
533 >>> parser = argparse.ArgumentParser(prog='PROG', conflict_handler='resolve')
544 Note that :class:`ArgumentParser` objects only remove an action if all of its
553 By default, ArgumentParser objects add an option which simply displays
558 parser = argparse.ArgumentParser()
562 If ``-h`` or ``--help`` is supplied at the command line, the ArgumentParser
576 :class:`ArgumentParser`::
578 >>> parser = argparse.ArgumentParser(prog='PROG', add_help=False)
592 >>> parser = argparse.ArgumentParser(prog='PROG', prefix_chars='+/')
603 .. method:: ArgumentParser.add_argument(name or flags..., [action], [nargs], \
643 The :meth:`~ArgumentParser.add_argument` method must know whether an optional
646 :meth:`~ArgumentParser.add_argument` must therefore be either a series of
656 When :meth:`~ArgumentParser.parse_args` is called, optional arguments will be
660 >>> parser = argparse.ArgumentParser(prog='PROG')
675 :class:`ArgumentParser` objects associate command-line arguments with actions. These
678 :meth:`~ArgumentParser.parse_args`. The ``action`` keyword argument specifies
684 >>> parser = argparse.ArgumentParser()
693 >>> parser = argparse.ArgumentParser()
703 >>> parser = argparse.ArgumentParser()
714 >>> parser = argparse.ArgumentParser()
725 >>> parser = argparse.ArgumentParser()
734 >>> parser = argparse.ArgumentParser()
741 added to the parser. See :class:`ArgumentParser` for details of how the
745 :meth:`~ArgumentParser.add_argument` call, and prints version information
749 >>> parser = argparse.ArgumentParser(prog='PROG')
770 >>> parser = argparse.ArgumentParser()
784 ArgumentParser objects usually associate a single command-line argument with a
792 >>> parser = argparse.ArgumentParser()
808 >>> parser = argparse.ArgumentParser()
821 >>> parser = argparse.ArgumentParser()
838 >>> parser = argparse.ArgumentParser()
849 >>> parser = argparse.ArgumentParser(prog='PROG')
863 >>> parser = argparse.ArgumentParser(prog='PROG')
878 The ``const`` argument of :meth:`~ArgumentParser.add_argument` is used to hold
880 the various :class:`ArgumentParser` actions. The two most common uses of it are:
882 * When :meth:`~ArgumentParser.add_argument` is called with
885 :meth:`~ArgumentParser.parse_args`. See the action_ description for examples.
887 * When :meth:`~ArgumentParser.add_argument` is called with option strings
903 :meth:`~ArgumentParser.add_argument`, whose value defaults to ``None``,
908 >>> parser = argparse.ArgumentParser()
920 >>> parser = argparse.ArgumentParser()
929 >>> parser = argparse.ArgumentParser()
940 >>> parser = argparse.ArgumentParser()
951 By default, :class:`ArgumentParser` objects read command-line arguments in as simple
954 ``type`` keyword argument of :meth:`~ArgumentParser.add_argument` allows any
958 >>> parser = argparse.ArgumentParser()
972 >>> parser = argparse.ArgumentParser()
988 >>> parser = argparse.ArgumentParser(prog='PROG')
999 >>> parser = argparse.ArgumentParser(prog='PROG')
1015 argument to :meth:`~ArgumentParser.add_argument`. When the command line is
1019 >>> parser = argparse.ArgumentParser(prog='game.py')
1032 >>> parser = argparse.ArgumentParser(prog='doors.py')
1051 keyword argument to :meth:`~ArgumentParser.add_argument`::
1053 >>> parser = argparse.ArgumentParser()
1062 :meth:`~ArgumentParser.parse_args` will report an error if that option is not
1079 >>> parser = argparse.ArgumentParser(prog='frobble')
1097 :meth:`~ArgumentParser.add_argument`, e.g. ``%(default)s``, ``%(type)s``, etc.::
1099 >>> parser = argparse.ArgumentParser(prog='frobble')
1114 >>> parser = argparse.ArgumentParser(prog='frobble')
1126 When :class:`ArgumentParser` generates help messages, it needs some way to refer
1127 to each expected argument. By default, ArgumentParser objects use the dest_
1135 >>> parser = argparse.ArgumentParser()
1152 >>> parser = argparse.ArgumentParser()
1168 attribute on the :meth:`~ArgumentParser.parse_args` object is still determined
1175 >>> parser = argparse.ArgumentParser(prog='PROG')
1190 Most :class:`ArgumentParser` actions add some value as an attribute of the
1191 object returned by :meth:`~ArgumentParser.parse_args`. The name of this
1193 :meth:`~ArgumentParser.add_argument`. For positional argument actions,
1195 :meth:`~ArgumentParser.add_argument`::
1197 >>> parser = argparse.ArgumentParser()
1203 the option strings. :class:`ArgumentParser` generates the value of ``dest`` by
1211 >>> parser = argparse.ArgumentParser()
1221 >>> parser = argparse.ArgumentParser()
1237 Action objects are used by an ArgumentParser to represent the information needed
1240 passed to :meth:`ArgumentParser.add_argument` except for the ``action`` itself.
1250 * ``parser`` - The ArgumentParser object which contains this action.
1253 :meth:`~ArgumentParser.parse_args`. Most actions add an attribute to this
1258 :meth:`~ArgumentParser.add_argument`.
1271 .. method:: ArgumentParser.parse_args(args=None, namespace=None)
1290 The :meth:`~ArgumentParser.parse_args` method supports several ways of
1294 >>> parser = argparse.ArgumentParser(prog='PROG')
1318 >>> parser = argparse.ArgumentParser(prog='PROG')
1329 While parsing the command line, :meth:`~ArgumentParser.parse_args` checks for a
1334 >>> parser = argparse.ArgumentParser(prog='PROG')
1357 The :meth:`~ArgumentParser.parse_args` method attempts to give errors whenever
1361 The :meth:`~ArgumentParser.parse_args` method is cautious here: positional
1365 >>> parser = argparse.ArgumentParser(prog='PROG')
1377 >>> parser = argparse.ArgumentParser(prog='PROG')
1397 :meth:`~ArgumentParser.parse_args` that everything after that is a positional
1408 The :meth:`~ArgumentParser.parse_args` method allows long options to be
1412 >>> parser = argparse.ArgumentParser(prog='PROG')
1430 Sometimes it may be useful to have an ArgumentParser parse arguments other than those
1432 :meth:`~ArgumentParser.parse_args`. This is useful for testing at the
1435 >>> parser = argparse.ArgumentParser()
1454 Simple class used by default by :meth:`~ArgumentParser.parse_args` to create
1461 >>> parser = argparse.ArgumentParser()
1467 It may also be useful to have an :class:`ArgumentParser` assign attributes to an
1475 >>> parser = argparse.ArgumentParser()
1488 .. method:: ArgumentParser.add_subparsers([title], [description], [prog], \
1498 :class:`ArgumentParser` supports the creation of such sub-commands with the
1501 has a single method, :meth:`~ArgumentParser.add_parser`, which takes a
1502 command name and any :class:`ArgumentParser` constructor arguments, and
1503 returns an :class:`ArgumentParser` object that can be modified as usual.
1519 default the class of the current parser (e.g. ArgumentParser)
1535 >>> parser = argparse.ArgumentParser(prog='PROG')
1600 >>> parser = argparse.ArgumentParser()
1631 >>> parser = argparse.ArgumentParser()
1662 >>> parser = argparse.ArgumentParser()
1678 argument of :meth:`ArgumentParser.add_argument`. Arguments that have
1682 >>> parser = argparse.ArgumentParser()
1691 >>> parser = argparse.ArgumentParser()
1700 .. method:: ArgumentParser.add_argument_group(title=None, description=None)
1702 By default, :class:`ArgumentParser` groups command-line arguments into
1708 >>> parser = argparse.ArgumentParser(prog='PROG', add_help=False)
1720 has an :meth:`~ArgumentParser.add_argument` method just like a regular
1721 :class:`ArgumentParser`. When an argument is added to the group, the parser
1727 >>> parser = argparse.ArgumentParser(prog='PROG', add_help=False)
1752 .. method:: ArgumentParser.add_mutually_exclusive_group(required=False)
1758 >>> parser = argparse.ArgumentParser(prog='PROG')
1774 >>> parser = argparse.ArgumentParser(prog='PROG')
1784 :meth:`~ArgumentParser.add_argument_group`.
1790 .. method:: ArgumentParser.set_defaults(**kwargs)
1798 >>> parser = argparse.ArgumentParser()
1806 >>> parser = argparse.ArgumentParser()
1813 parsers. See the :meth:`~ArgumentParser.add_subparsers` method for an
1816 .. method:: ArgumentParser.get_default(dest)
1819 :meth:`~ArgumentParser.add_argument` or by
1820 :meth:`~ArgumentParser.set_defaults`::
1822 >>> parser = argparse.ArgumentParser()
1831 In most typical applications, :meth:`~ArgumentParser.parse_args` will take
1835 .. method:: ArgumentParser.print_usage(file=None)
1837 Print a brief description of how the :class:`ArgumentParser` should be
1841 .. method:: ArgumentParser.print_help(file=None)
1844 arguments registered with the :class:`ArgumentParser`. If *file* is
1850 .. method:: ArgumentParser.format_usage()
1853 :class:`ArgumentParser` should be invoked on the command line.
1855 .. method:: ArgumentParser.format_help()
1858 information about the arguments registered with the :class:`ArgumentParser`.
1864 .. method:: ArgumentParser.parse_known_args(args=None, namespace=None)
1868 :meth:`~ArgumentParser.parse_known_args` method can be useful. It works much like
1869 :meth:`~ArgumentParser.parse_args` except that it does not produce an error when
1875 >>> parser = argparse.ArgumentParser()
1891 .. method:: ArgumentParser.convert_arg_line_to_args(arg_line)
1894 keyword argument to the :class:`ArgumentParser` constructor) are read one
1912 .. method:: ArgumentParser.exit(status=0, message=None)
1917 .. method:: ArgumentParser.error(message)
1948 :meth:`ArgumentParser.add_argument` calls.
1951 parser.parse_args()`` and add additional :meth:`ArgumentParser.add_argument`
1957 use :meth:`~ArgumentParser.parse_known_args` to collect unparsed argument