[Python-bugs-list] [ python-Bugs-729096 ] getopt online documentation example improvement
SourceForge.net
noreply@sourceforge.net
Mon, 28 Apr 2003 21:38:15 -0700
Bugs item #729096, was opened at 2003-04-28 13:37
Message generated for change (Comment added) made by rhettinger
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=729096&group_id=5470
Category: Documentation
Group: None
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Ben Hartshorne (b655321)
Assigned to: Nobody/Anonymous (nobody)
Summary: getopt online documentation example improvement
Initial Comment:
The online documentation for the getopt module
(http://www.python.org/doc/current/lib/module-getopt.html)
has the following example:
for o, a in opts:
if o in ("-h", "--help"):
usage()
sys.exit()
if o in ("-o", "--output"):
output = a
# ...
As a python newbie, I was trying to use this example,
but I had only short options in my program. It took me
quite a bit of confusion to realize that the third form
below is correct. While this may be obvious to people
experienced in python (that this actually must be a
tuple of a single element, which only the third if()
statement below creates), it caused me quite a bit of
frustration.
for o, a in opts:
if o in "-i":
input_file = a
if(o in ("-o"):
output_file = a
if(o in ("-s",):
source_file = a
if(o in ("-h", "--help")):
print_usage()
sys.exit()
I would like to suggest that the example in the
documentation include three if o in ... statements: one
with only a short option, one with both, and one with
only a long option.
-ben
sourceforge@green.hartshorne.net
----------------------------------------------------------------------
>Comment By: Raymond Hettinger (rhettinger)
Date: 2003-04-28 23:38
Message:
Logged In: YES
user_id=80475
Fixed example.
See libgetopt.tex 1.21 and 1.19.8.1
Thanks for the bug report!
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=729096&group_id=5470