you didn't read the documentation for getopt.getopt
:
getopt.getopt(args, options[, long_options])
Parses command line options and parameter list. [...]
long_options
, if specified, must be a list of strings with the names of the long options which should be supported. The leading --
characters should not be included in the option name. Long options
which require an argument should be followed by an equal sign (=
).
Optional arguments are not supported. To accept only long options,
options
should be an empty string.
so you have to do:
options, args = getopt.getopt(sys.argv[1:], "", ['empid='])
Quoting from the documentation of getopt
:
Note
The getopt
module is a parser for command line options whose API is
designed to be familiar to users of the C getopt()
function. Users
who are unfamiliar with the C getopt()
function or who would like to
write less code and get better help and error messages should consider using the argparse
module instead.
Example of usage of argparse
:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--empid', type=int)
parser.add_argument('positionals', nargs='*')
args = parser.parse_args()
print(args.positionals, args.empid)
This module is much more flexible, advanced and, at the same time, easier to use than getopt
.