Argparse Tutorial

Ke Gui
1 min readJun 6, 2020

--

This is the best argparse tutorial I ever seen.

We need to check the add_argument() method in ArgumentParser.add_argument():

ArgumentParser.add_argument(name or flags...[, action][, nargs][, const][, default][, type][, choices][, required][, help][, metavar][, dest])
  1. name or flags — Either a name or a list of option strings, e.g. foo or -f, — foo.
  2. action — The basic type of action to be taken when this argument is encountered at the command line.
  3. nargs — The number of command-line arguments that should be consumed.
  4. const — A constant value required by some action and nargs selections.
  5. default — The value produced if the argument is absent from the command line.
  6. type — The type to which the command-line argument should be converted.
  7. choices — A container of the allowable values for the argument.
  8. required — Whether or not the command-line option may be omitted (optionals only).
  9. help — A brief description of what the argument does.
  10. metavar — A name for the argument in usage messages.
  11. dest — The name of the attribute to be added to the object returned by parse_args().

--

--

Ke Gui
Ke Gui

Written by Ke Gui

An ordinary guy who wants to be the reason someone believes in the goodness of people. He is living at Brisbane, Australia, with a lovely backyard.

No responses yet