The general approach to using argparse involves the following four steps:
- First, we create an ArgumentParser instance. We can provide this object with overall information about the command-line interface. This might include a description, format changes for the displayed options and arguments, and whether or not -h is the help option. Generally, we only need to provide the description; the rest of the options have sensible defaults.
- Then, we define the command-line options and arguments. This is done by adding arguments with the ArgumentParser.add_argument() method function.
- Next, we parse the sys.argv command line to create a namespace object that details the options, option arguments, and overall command-line arguments.
- Lastly, we use the namespace object to configure the application and process the arguments. There are a number of alternative...