Commit b68cfdd3 authored by Georg Brandl's avatar Georg Brandl

Bug #1601630: little improvement to getopt docs

parent 6a199545
...@@ -126,8 +126,9 @@ import getopt, sys ...@@ -126,8 +126,9 @@ import getopt, sys
def main(): def main():
try: try:
opts, args = getopt.getopt(sys.argv[1:], "ho:v", ["help", "output="]) opts, args = getopt.getopt(sys.argv[1:], "ho:v", ["help", "output="])
except getopt.GetoptError: except getopt.GetoptError, err:
# print help information and exit: # print help information and exit:
print str(err) # will print something like "option -a not recognized"
usage() usage()
sys.exit(2) sys.exit(2)
output = None output = None
...@@ -135,11 +136,13 @@ def main(): ...@@ -135,11 +136,13 @@ def main():
for o, a in opts: for o, a in opts:
if o == "-v": if o == "-v":
verbose = True verbose = True
if o in ("-h", "--help"): elif o in ("-h", "--help"):
usage() usage()
sys.exit() sys.exit()
if o in ("-o", "--output"): elif o in ("-o", "--output"):
output = a output = a
else:
assert False, "unhandled option"
# ... # ...
if __name__ == "__main__": if __name__ == "__main__":
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment