Lines Matching refs:argparse
1 :mod:`argparse` --- Parser for command-line options, arguments and sub-commands
4 .. module:: argparse
12 **Source code:** :source:`Lib/argparse.py`
20 :ref:`argparse tutorial <argparse-tutorial>`.
22 The :mod:`argparse` module makes it easy to write user-friendly command-line
23 interfaces. The program defines what arguments it requires, and :mod:`argparse`
24 will figure out how to parse those out of :data:`sys.argv`. The :mod:`argparse`
35 import argparse
37 parser = argparse.ArgumentParser(description='Process some integers.')
89 The first step in using the :mod:`argparse` is creating an
92 >>> parser = argparse.ArgumentParser(description='Process some integers.')
142 formatter_class=argparse.HelpFormatter, \
197 import argparse
198 parser = argparse.ArgumentParser()
224 >>> parser = argparse.ArgumentParser(prog='myprogram')
237 >>> parser = argparse.ArgumentParser(prog='myprogram')
253 >>> parser = argparse.ArgumentParser(prog='PROG')
268 >>> parser = argparse.ArgumentParser(prog='PROG', usage='%(prog)s [options]')
294 >>> parser = argparse.ArgumentParser(description='A foo that bars')
296 usage: argparse.py [-h]
314 >>> parser = argparse.ArgumentParser(
318 usage: argparse.py [-h]
342 >>> parent_parser = argparse.ArgumentParser(add_help=False)
345 >>> foo_parser = argparse.ArgumentParser(parents=[parent_parser])
350 >>> bar_parser = argparse.ArgumentParser(parents=[parent_parser])
382 >>> parser = argparse.ArgumentParser(
406 >>> parser = argparse.ArgumentParser(
408 ... formatter_class=argparse.RawDescriptionHelpFormatter,
436 >>> parser = argparse.ArgumentParser(
438 ... formatter_class=argparse.ArgumentDefaultsHelpFormatter)
455 >>> parser = argparse.ArgumentParser(
457 ... formatter_class=argparse.MetavarTypeHelpFormatter)
480 >>> parser = argparse.ArgumentParser(prog='PROG', prefix_chars='-+')
503 >>> parser = argparse.ArgumentParser(fromfile_prefix_chars='@')
530 >>> parser = argparse.ArgumentParser(argument_default=argparse.SUPPRESS)
549 >>> parser = argparse.ArgumentParser(prog='PROG', allow_abbrev=False)
567 >>> parser = argparse.ArgumentParser(prog='PROG')
579 >>> parser = argparse.ArgumentParser(prog='PROG', conflict_handler='resolve')
603 import argparse
604 parser = argparse.ArgumentParser()
624 >>> parser = argparse.ArgumentParser(prog='PROG', add_help=False)
638 >>> parser = argparse.ArgumentParser(prog='PROG', prefix_chars='+/')
706 >>> parser = argparse.ArgumentParser(prog='PROG')
730 >>> parser = argparse.ArgumentParser()
739 >>> parser = argparse.ArgumentParser()
749 >>> parser = argparse.ArgumentParser()
760 >>> parser = argparse.ArgumentParser()
771 >>> parser = argparse.ArgumentParser()
780 >>> parser = argparse.ArgumentParser()
794 >>> import argparse
795 >>> parser = argparse.ArgumentParser(prog='PROG')
807 >>> class FooAction(argparse.Action):
816 >>> parser = argparse.ArgumentParser()
838 >>> parser = argparse.ArgumentParser()
847 .. index:: single: ? (question mark); in argparse module
856 >>> parser = argparse.ArgumentParser()
869 >>> parser = argparse.ArgumentParser()
870 >>> parser.add_argument('infile', nargs='?', type=argparse.FileType('r'),
872 >>> parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'),
881 .. index:: single: * (asterisk); in argparse module
888 >>> parser = argparse.ArgumentParser()
895 .. index:: single: + (plus); in argparse module
901 >>> parser = argparse.ArgumentParser(prog='PROG')
909 .. _`argparse.REMAINDER`:
911 * ``argparse.REMAINDER``. All the remaining command-line arguments are gathered
915 >>> parser = argparse.ArgumentParser(prog='PROG')
918 >>> parser.add_argument('args', nargs=argparse.REMAINDER)
960 >>> parser = argparse.ArgumentParser()
972 >>> parser = argparse.ArgumentParser()
981 >>> parser = argparse.ArgumentParser()
989 Providing ``default=argparse.SUPPRESS`` causes no attribute to be added if the
992 >>> parser = argparse.ArgumentParser()
993 >>> parser.add_argument('--foo', default=argparse.SUPPRESS)
1010 >>> parser = argparse.ArgumentParser()
1019 To ease the use of various types of files, the argparse module provides the
1024 >>> parser = argparse.ArgumentParser()
1025 >>> parser.add_argument('bar', type=argparse.FileType('w'))
1037 ... raise argparse.ArgumentTypeError(msg)
1040 >>> parser = argparse.ArgumentParser(prog='PROG')
1051 >>> parser = argparse.ArgumentParser(prog='PROG')
1071 >>> parser = argparse.ArgumentParser(prog='game.py')
1084 >>> parser = argparse.ArgumentParser(prog='doors.py')
1100 In general, the :mod:`argparse` module assumes that flags like ``-f`` and ``--bar``
1105 >>> parser = argparse.ArgumentParser()
1110 usage: argparse.py [-h] [--foo FOO]
1111 argparse.py: error: option --foo is required
1131 >>> parser = argparse.ArgumentParser(prog='frobble')
1151 >>> parser = argparse.ArgumentParser(prog='frobble')
1166 :mod:`argparse` supports silencing the help entry for certain options, by
1167 setting the ``help`` value to ``argparse.SUPPRESS``::
1169 >>> parser = argparse.ArgumentParser(prog='frobble')
1170 >>> parser.add_argument('--foo', help=argparse.SUPPRESS)
1190 >>> parser = argparse.ArgumentParser()
1207 >>> parser = argparse.ArgumentParser()
1230 >>> parser = argparse.ArgumentParser(prog='PROG')
1252 >>> parser = argparse.ArgumentParser()
1266 >>> parser = argparse.ArgumentParser()
1276 >>> parser = argparse.ArgumentParser()
1351 >>> parser = argparse.ArgumentParser(prog='PROG')
1375 >>> parser = argparse.ArgumentParser(prog='PROG')
1391 >>> parser = argparse.ArgumentParser(prog='PROG')
1422 >>> parser = argparse.ArgumentParser(prog='PROG')
1434 >>> parser = argparse.ArgumentParser(prog='PROG')
1469 >>> parser = argparse.ArgumentParser(prog='PROG')
1493 >>> parser = argparse.ArgumentParser()
1519 >>> parser = argparse.ArgumentParser()
1533 >>> parser = argparse.ArgumentParser()
1596 >>> parser = argparse.ArgumentParser(prog='PROG')
1661 >>> parser = argparse.ArgumentParser()
1682 >>> parser = argparse.ArgumentParser()
1702 >>> parser = argparse.ArgumentParser()
1733 >>> parser = argparse.ArgumentParser()
1754 >>> parser = argparse.ArgumentParser()
1755 >>> parser.add_argument('--raw', type=argparse.FileType('wb', 0))
1756 >>> parser.add_argument('out', type=argparse.FileType('w', encoding='UTF-8'))
1764 >>> parser = argparse.ArgumentParser()
1765 >>> parser.add_argument('infile', type=argparse.FileType('r'))
1784 >>> parser = argparse.ArgumentParser(prog='PROG', add_help=False)
1803 >>> parser = argparse.ArgumentParser(prog='PROG', add_help=False)
1830 Create a mutually exclusive group. :mod:`argparse` will make sure that only
1834 >>> parser = argparse.ArgumentParser(prog='PROG')
1850 >>> parser = argparse.ArgumentParser(prog='PROG')
1874 >>> parser = argparse.ArgumentParser()
1882 >>> parser = argparse.ArgumentParser()
1898 >>> parser = argparse.ArgumentParser()
1951 >>> parser = argparse.ArgumentParser()
1981 class MyArgumentParser(argparse.ArgumentParser):
2011 These parsers do not support all the argparse features, and will raise
2013 ``argparse.REMAINDER``, and mutually exclusive groups that include both
2022 >>> parser = argparse.ArgumentParser()
2043 Originally, the :mod:`argparse` module had attempted to maintain compatibility
2050 The :mod:`argparse` module improves on the standard library :mod:`optparse`
2060 A partial upgrade path from :mod:`optparse` to :mod:`argparse`:
2068 called ``options``, now in the :mod:`argparse` context is called ``args``.