• Home
  • Raw
  • Download

Lines Matching refs:argparse

1 :mod:`argparse` --- Parser for command-line options, arguments and sub-commands
4 .. module:: argparse
11 **Source code:** :source:`Lib/argparse.py`
19 :ref:`argparse tutorial <argparse-tutorial>`.
21 The :mod:`argparse` module makes it easy to write user-friendly command-line
22 interfaces. The program defines what arguments it requires, and :mod:`argparse`
23 will figure out how to parse those out of :data:`sys.argv`. The :mod:`argparse`
34 import argparse
36 parser = argparse.ArgumentParser(description='Process some integers.')
88 The first step in using the :mod:`argparse` is creating an
91 >>> parser = argparse.ArgumentParser(description='Process some integers.')
141 formatter_class=argparse.HelpFormatter, \
190 import argparse
191 parser = argparse.ArgumentParser()
217 >>> parser = argparse.ArgumentParser(prog='myprogram')
230 >>> parser = argparse.ArgumentParser(prog='myprogram')
246 >>> parser = argparse.ArgumentParser(prog='PROG')
261 >>> parser = argparse.ArgumentParser(prog='PROG', usage='%(prog)s [options]')
287 >>> parser = argparse.ArgumentParser(description='A foo that bars')
289 usage: argparse.py [-h]
307 >>> parser = argparse.ArgumentParser(
311 usage: argparse.py [-h]
335 >>> parent_parser = argparse.ArgumentParser(add_help=False)
338 >>> foo_parser = argparse.ArgumentParser(parents=[parent_parser])
343 >>> bar_parser = argparse.ArgumentParser(parents=[parent_parser])
375 >>> parser = argparse.ArgumentParser(
399 >>> parser = argparse.ArgumentParser(
401 ... formatter_class=argparse.RawDescriptionHelpFormatter,
429 >>> parser = argparse.ArgumentParser(
431 ... formatter_class=argparse.ArgumentDefaultsHelpFormatter)
454 >>> parser = argparse.ArgumentParser(prog='PROG', prefix_chars='-+')
477 >>> parser = argparse.ArgumentParser(fromfile_prefix_chars='@')
504 >>> parser = argparse.ArgumentParser(argument_default=argparse.SUPPRESS)
521 >>> parser = argparse.ArgumentParser(prog='PROG')
533 >>> parser = argparse.ArgumentParser(prog='PROG', conflict_handler='resolve')
557 import argparse
558 parser = argparse.ArgumentParser()
578 >>> parser = argparse.ArgumentParser(prog='PROG', add_help=False)
592 >>> parser = argparse.ArgumentParser(prog='PROG', prefix_chars='+/')
660 >>> parser = argparse.ArgumentParser(prog='PROG')
684 >>> parser = argparse.ArgumentParser()
693 >>> parser = argparse.ArgumentParser()
703 >>> parser = argparse.ArgumentParser()
714 >>> parser = argparse.ArgumentParser()
725 >>> parser = argparse.ArgumentParser()
734 >>> parser = argparse.ArgumentParser()
748 >>> import argparse
749 >>> parser = argparse.ArgumentParser(prog='PROG')
761 >>> class FooAction(argparse.Action):
770 >>> parser = argparse.ArgumentParser()
792 >>> parser = argparse.ArgumentParser()
808 >>> parser = argparse.ArgumentParser()
821 >>> parser = argparse.ArgumentParser()
822 >>> parser.add_argument('infile', nargs='?', type=argparse.FileType('r'),
824 >>> parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'),
838 >>> parser = argparse.ArgumentParser()
849 >>> parser = argparse.ArgumentParser(prog='PROG')
857 .. _`argparse.REMAINDER`:
859 * ``argparse.REMAINDER``. All the remaining command-line arguments are gathered
863 >>> parser = argparse.ArgumentParser(prog='PROG')
866 >>> parser.add_argument('args', nargs=argparse.REMAINDER)
908 >>> parser = argparse.ArgumentParser()
920 >>> parser = argparse.ArgumentParser()
929 >>> parser = argparse.ArgumentParser()
937 Providing ``default=argparse.SUPPRESS`` causes no attribute to be added if the
940 >>> parser = argparse.ArgumentParser()
941 >>> parser.add_argument('--foo', default=argparse.SUPPRESS)
958 >>> parser = argparse.ArgumentParser()
967 To ease the use of various types of files, the argparse module provides the
972 >>> parser = argparse.ArgumentParser()
973 >>> parser.add_argument('bar', type=argparse.FileType('w'))
985 ... raise argparse.ArgumentTypeError(msg)
988 >>> parser = argparse.ArgumentParser(prog='PROG')
999 >>> parser = argparse.ArgumentParser(prog='PROG')
1019 >>> parser = argparse.ArgumentParser(prog='game.py')
1032 >>> parser = argparse.ArgumentParser(prog='doors.py')
1048 In general, the :mod:`argparse` module assumes that flags like ``-f`` and ``--bar``
1053 >>> parser = argparse.ArgumentParser()
1058 usage: argparse.py [-h] [--foo FOO]
1059 argparse.py: error: option --foo is required
1079 >>> parser = argparse.ArgumentParser(prog='frobble')
1099 >>> parser = argparse.ArgumentParser(prog='frobble')
1111 :mod:`argparse` supports silencing the help entry for certain options, by
1112 setting the ``help`` value to ``argparse.SUPPRESS``::
1114 >>> parser = argparse.ArgumentParser(prog='frobble')
1115 >>> parser.add_argument('--foo', help=argparse.SUPPRESS)
1135 >>> parser = argparse.ArgumentParser()
1152 >>> parser = argparse.ArgumentParser()
1175 >>> parser = argparse.ArgumentParser(prog='PROG')
1197 >>> parser = argparse.ArgumentParser()
1211 >>> parser = argparse.ArgumentParser()
1221 >>> parser = argparse.ArgumentParser()
1294 >>> parser = argparse.ArgumentParser(prog='PROG')
1318 >>> parser = argparse.ArgumentParser(prog='PROG')
1334 >>> parser = argparse.ArgumentParser(prog='PROG')
1365 >>> parser = argparse.ArgumentParser(prog='PROG')
1377 >>> parser = argparse.ArgumentParser(prog='PROG')
1412 >>> parser = argparse.ArgumentParser(prog='PROG')
1435 >>> parser = argparse.ArgumentParser()
1461 >>> parser = argparse.ArgumentParser()
1475 >>> parser = argparse.ArgumentParser()
1535 >>> parser = argparse.ArgumentParser(prog='PROG')
1600 >>> parser = argparse.ArgumentParser()
1631 >>> parser = argparse.ArgumentParser()
1662 >>> parser = argparse.ArgumentParser()
1682 >>> parser = argparse.ArgumentParser()
1683 >>> parser.add_argument('--output', type=argparse.FileType('wb', 0))
1691 >>> parser = argparse.ArgumentParser()
1692 >>> parser.add_argument('infile', type=argparse.FileType('r'))
1708 >>> parser = argparse.ArgumentParser(prog='PROG', add_help=False)
1727 >>> parser = argparse.ArgumentParser(prog='PROG', add_help=False)
1754 Create a mutually exclusive group. :mod:`argparse` will make sure that only
1758 >>> parser = argparse.ArgumentParser(prog='PROG')
1774 >>> parser = argparse.ArgumentParser(prog='PROG')
1798 >>> parser = argparse.ArgumentParser()
1806 >>> parser = argparse.ArgumentParser()
1822 >>> parser = argparse.ArgumentParser()
1875 >>> parser = argparse.ArgumentParser()
1928 Originally, the :mod:`argparse` module had attempted to maintain compatibility
1935 The :mod:`argparse` module improves on the standard library :mod:`optparse`
1945 A partial upgrade path from :mod:`optparse` to :mod:`argparse`:
1953 called ``options``, now in the :mod:`argparse` context is called ``args``.
1956 by setting ``nargs`` of a positional argument to `argparse.REMAINDER`_, or