[Python-bugs-list] [ python-Bugs-729096 ] getopt online documentation example improvement
SourceForge.net
noreply@sourceforge.net
Mon, 28 Apr 2003 11:37:29 -0700
Bugs item #729096, was opened at 2003-04-28 11:37
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=729096&group_id=5470
Category: Documentation
Group: None
Status: Open
Resolution: None
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
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=729096&group_id=5470