]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
SF bug #729096: getopt online documentation example improvement
authorRaymond Hettinger <python@rcn.com>
Tue, 29 Apr 2003 04:37:13 +0000 (04:37 +0000)
committerRaymond Hettinger <python@rcn.com>
Tue, 29 Apr 2003 04:37:13 +0000 (04:37 +0000)
A newbie found it difficult to translate the exampe into a
case that used only short options or long options but not both.
He tried to shorten the tuple search but forgot the trailing comma,
The appropriate pattern is an equality check.

Revised the example to point him in the right direction.

Doc/lib/libgetopt.tex

index 1348921f56eb84b1a47b47e55f32ac61f058874a..c1763c5fc2429c5a5a812c9199b602828f935110 100644 (file)
@@ -111,13 +111,16 @@ import getopt, sys
 
 def main():
     try:
-        opts, args = getopt.getopt(sys.argv[1:], "ho:", ["help", "output="])
+        opts, args = getopt.getopt(sys.argv[1:], "ho:v", ["help", "output="])
     except getopt.GetoptError:
         # print help information and exit:
         usage()
         sys.exit(2)
     output = None
+    verbose = False
     for o, a in opts:
+        if o == "-v":
+            verbose = True
         if o in ("-h", "--help"):
             usage()
             sys.exit()