This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Marshall Giguere
Recipients Marshall Giguere
Date 2017-03-01.03:32:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1488339150.93.0.468964367944.issue29681@psf.upfronthosting.co.za>
In-reply-to
Content
Python 3.4.3 (default, Nov 17 2016, 01:08:31) 
[GCC 4.8.4] on linux
>>> from getopt import getopt
>>> argv = [ '-a', '-b', '-c', '-d', 'foo']
>>> opts, args = getopt( argv, 'abc:d:')
>>> opts
[('-a', ''), ('-b', ''), ('-c', '-d')]
>>> args
['foo']

Expected behavior:
opts = [('-a', ''), ('-b', ''), ('-c', ''), ('-d', 'foo')]
Throws execption:
getopt.GetoptError: option -c requires argument

Note that -c requires a value, getopt swallows the next option '-d' as the argument to -c.  However, if -c is the last option on the command line getopt properly throws an execption "getopt.GetoptError: option -c requires argument".

The documentation states that getopt will throw an exception when an option requiring a value is missing and exception will be thrown.
"exception getopt.GetoptError
This is raised when an unrecognized option is found in the argument list or when an option requiring an argument is given none."

The option -c requires an argument, none was given, no exception is thrown.  Instead the next option, '-d', is taken as the argument.  I have also tried this test on 2.7 with the same result.
History
Date User Action Args
2017-03-01 03:32:30Marshall Gigueresetrecipients: + Marshall Giguere
2017-03-01 03:32:30Marshall Gigueresetmessageid: <1488339150.93.0.468964367944.issue29681@psf.upfronthosting.co.za>
2017-03-01 03:32:30Marshall Giguerelinkissue29681 messages
2017-03-01 03:32:30Marshall Giguerecreate