mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
Bug #1601630: little improvement to getopt docs
This commit is contained in:
parent
39b8b6afb5
commit
3f969022c6
1 changed files with 6 additions and 3 deletions
|
@ -126,8 +126,9 @@ import getopt, sys
|
|||
def main():
|
||||
try:
|
||||
opts, args = getopt.getopt(sys.argv[1:], "ho:v", ["help", "output="])
|
||||
except getopt.GetoptError:
|
||||
except getopt.GetoptError, err:
|
||||
# print help information and exit:
|
||||
print str(err) # will print something like "option -a not recognized"
|
||||
usage()
|
||||
sys.exit(2)
|
||||
output = None
|
||||
|
@ -135,11 +136,13 @@ def main():
|
|||
for o, a in opts:
|
||||
if o == "-v":
|
||||
verbose = True
|
||||
if o in ("-h", "--help"):
|
||||
elif o in ("-h", "--help"):
|
||||
usage()
|
||||
sys.exit()
|
||||
if o in ("-o", "--output"):
|
||||
elif o in ("-o", "--output"):
|
||||
output = a
|
||||
else:
|
||||
assert False, "unhandled option"
|
||||
# ...
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue