I left out the Usage class
class Usage(Exception):
def __init__(self, msg):
self.msg = msg
I seem to be missing a post.
Here is the code.
class Usage(Exception):
def __init__(self, msg):
self.msg = msg
def main(argv=None):
help_message = \
("\nOtFixture.py:\n Set the Optics Test Fixture Light Source Light
Level\n" +
"Options:\n"
" -l, --level= <The light level percent of Max: 0.0 to 100.0>\n"
+
" -v, --verbose: Print messages to the terminal.\n"
" -h, --help: This message\n")
level = None
verbose = False
helpflag = False
options = "hl:v"
long_options = ["help","level=","verbose"]
if argv is None:
argv = sys.argv
try:
try:
opts, _args = getopt.getopt(argv[1:],
options,long_options)
except getopt.error, msg:
raise Usage(msg)
for o, a in opts:
if o in ("-h", "--help"):
print help_message
helpflag = True
elif o in ("-l", "--level"):
level = a
elif o in ("-v", "--verbose"):
verbose = True
else:
assert False, "unhandled option"
if not helpflag:
if level == None:
level = raw_input("Enter the light level from 0.0 to
100.0%: ")
if level.replace(".", "", 1).isdigit():
level = float(level)
else:
msg = "\n" + str(level) + " is not a number.\n"
raise Usage(msg)
if verbose and level is not None:
print "The level is ", level, " percent"
if level is not None:
if 0.0 <= level <= 100.0:
ot = OtFixture(verbose)
ot.setLightLevel(level)
print "Light Level set to ", level,"%."
else:
msg = "\n" + str(level) + " is not in the range 0.0 to
100.0%\n"
raise Usage(msg)
except Usage, err:
print >>sys.stderr, err.msg
print >>sys.stderr, "for help use --help"
return 2
if __name__ == "__main__":
sys.exit(main())
I don't really have a problem. I'm was just curious.
How do you invoke python -O? When I run python.exe -O OtFixture.py -q,
I get the same response. It's a capital letter O, right?