15.5. getopt — Parser for command line options

This module helps scripts to parse the command line arguments in sys.argv. It supports the same conventions as the Unix getopt() function (including the special meanings of arguments of the form ‘-‘ and ‘--‘). Long options similar to those supported by GNU software may be used as well via an optional third argument.

A more convenient, flexible, and powerful alternative is the optparse module.

This module provides two functions and an exception:

An example using only Unix style options:

Using long option names is equally easy:

In a script, typical usage is something like this:

See also

 

https://docs.python.org/3.1/library/getopt.html