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

noreply@sourceforge.net noreply@sourceforge.net
Wed, 11 Apr 2001 00:33:54 -0700


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: Documentation
Group: None
>Status: Closed
Priority: 5
Submitted By: Gregor Hoffleit (flight)
Assigned to: Moshe Zadka (moshez)
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.


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

>Comment By: Moshe Zadka (moshez)
Date: 2001-04-11 00:33

Message:
Logged In: YES 
user_id=11645

Checked in as libgetopt.tex v 1.17

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

Comment By: Fred L. Drake, Jr. (fdrake)
Date: 2001-03-18 08:27

Message:
Logged In: YES 
user_id=3066

Moshe:  Your documentation update is correct; please check it in.

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

Comment By: Moshe Zadka (moshez)
Date: 2001-03-18 03:46

Message:
Logged In: YES 
user_id=11645

This patches clarifies the documentation, that the "GNU
behaviour" comment only holds for interpretation of --
options and *not* to the ordering problem.

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

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