[Python-bugs-list] [ python-Bugs-405999 ] getopt: extra args behavior wrong

noreply@sourceforge.net noreply@sourceforge.net
Fri, 16 Mar 2001 09:52:49 -0800


Bugs item #405999, was updated on 2001-03-05 03:42
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=405999&group_id=5470

Category: Python Library
Group: None
Status: Open
Priority: 5
Submitted By: Gregor Hoffleit (flight)
>Assigned to: Fred L. Drake, Jr. (fdrake)
Summary: getopt: extra args behavior wrong

Initial Comment:
[Forwarded from the Debian bug tracking system,
Bug#87722]
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=87722&repeatmerged=yes

Sender: Wichert Akkerman <wichert@cistron.nl>

getopt claims to behave just like GNU getopt, but it
does not. If I use
this code snippet:

------------------------------------------------------------------------------
(opt,args) = getopt.getopt(sys.argv[1:], 'ab')

print "Options decoded: " + string.join(map(lambda x:
x[0], opt), ', ')
print "Extra arguments: " +  string.join(args, ', ')
------------------------------------------------------------------------------

Then this result is correct:

[fog;/tmp]-26> ./x.py -a -b bla
Options decoded: -a, -b
Extra arguments: bla

But this is wrong:

[fog;/tmp]-27> ./x.py -a bla -b 
Options decoded: -a
Extra arguments: bla, -b

That should give the exact same result, but doesn't.
The problem seems
to be that the while loop used to iterate over the
arguments aborts
at the first non-option argument, while it should
continue to check
all arguments for possible options.

This problem persist in python2-base.

Wichert.


----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=405999&group_id=5470