This page arguments against software testing the API reference information. Assuming the Python code above is saved into a file called prog.
The following sections walk you through this example. This will inspect the command line, convert each argument to the appropriate type and then invoke the appropriate action. All parameters should be passed as keyword arguments. The following sections describe how each of these are used. This default is almost always desirable because it will make the help messages match how the program was invoked on the command line. For example, consider a file named myprogram. The help for this program will display myprogram.
Note that the program name, whether determined from sys. This argument gives a brief description of what the program does and how it works. By default, the description will be line-wrapped so that it fits within the given space. To change this behavior, see the formatter_class argument. Some programs like to display additional description of the program after the description of the arguments. Sometimes, several parsers share a common set of arguments.
If you change the parent parsers after the child parser, those changes will not be reflected in the child. Please do not mess up this text! However, multiple new lines are replaced with one. If you wish to preserve multiple blank lines, add spaces between the newlines. Parsers that need to support different or additional prefix characters, e.
Sometimes, for example when dealing with a particularly long argument lists, it may make sense to keep the list of arguments in a file rather than typing it out at the command line. Sometimes however, it may be useful to specify a single parser-wide default for arguments. Occasionally, it may be useful to disable the addition of this help option. Define how a single command-line argument should be parsed.
Either a name or a list of option strings, e. The basic type of action to be taken when this argument is encountered at the command line. The number of command-line arguments that should be consumed. A constant value required by some action and nargs selections. The value produced if the argument is absent from the command line.
The type to which the command-line argument should be converted. A container of the allowable values for the argument. A brief description of what the argument does. A name for the argument in usage messages. This just stores the argument’s value. This stores the value specified by the const keyword argument. This stores a list, and appends each argument value to the list.