1 \section{Standard Module
\sectcode{getopt
}}
4 This module helps scripts to parse the command line arguments in
6 It uses the same conventions as the
\UNIX{}
8 function (including the special meanings of arguments of the form
9 \samp{-
} and
\samp{--
}).
10 It defines the function
11 \code{getopt.getopt(args, options)
}
17 is the argument list passed to the script with its first element
20 The second argument is the string of option letters that the
21 script wants to recognize, with options that require an argument
22 followed by a colon (i.e., the same format that
\UNIX{}
25 The return value consists of two elements: the first is a list of
26 option-and-value pairs; the second is the list of program arguments
27 left after the option list was stripped (this is a trailing slice of the
29 Each option-and-value pair returned has the option as its first element,
30 prefixed with a hyphen (e.g.,
32 and the option argument as its second element, or an empty string if the
33 option has no argument.
34 The options occur in the list in the same order in which they were
35 found, thus allowing multiple occurrences.
38 \bcode\begin{verbatim
}
39 >>> import getopt, string
40 >>> args = string.split('-a -b -cfoo -d bar a1 a2')
42 ['-a', '-b', '-cfoo', '-d', 'bar', 'a1', 'a2'
]
43 >>> optlist, args = getopt.getopt(args, 'abc:d:')
45 [('-a', ''), ('-b', ''), ('-c', 'foo'), ('-d', 'bar')
]
52 \code{getopt.error = 'getopt error'
}
53 is raised when an unrecognized option is found in the argument list or
54 when an option requiring an argument is given none.
55 The argument to the exception is a string indicating the cause of the