Python getopt Module
Example
Parse short options with an argument list:
import getopt
opts, args = getopt.getopt(["-a", "-b", "Linus"], "ab:")
print(dict(sorted(opts)))
print(args)
Try it Yourself »
Definition and Usage
The getopt module parses command-line options and parameters.
It supports Unix-style short options and GNU-style long options via getopt() and gnu_getopt().
Members
| Member | Description |
|---|---|
| getopt() | Parse command-line options (short and long). |
| gnu_getopt() | Variant of getopt() that allows options and arguments to be intermixed. |
| GetoptError | Exception raised for parsing errors. |