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 steven.daprano
Recipients berker.peksag, r.david.murray, serhiy.storchaka, steven.daprano
Date 2016-07-26.17:06:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <20160726170614.GV27919@ando.pearwood.info>
In-reply-to <1469546849.42.0.690376448276.issue27619@psf.upfronthosting.co.za>
Content
On Tue, Jul 26, 2016 at 03:27:29PM +0000, R. David Murray wrote:
[...]
> getopt is explicitly emulating the C getopt

There are lots of differences between the C getopt and the Python 
version, and the Python version is described as offering an API 
"designed to be familiar" to uses of the C version, not to emulate all 
the idiosyncrasies of the C version. For instance, the Python version 
raises an exception on errors, rather than returning -1; the C version 
requires argc ("argument count"), but the Python version doesn't.

But most critically, the C version DOES strip whitespace from long 
arguments. On my Centos box, it only strips *trailing* spaces, not 
leading spaces, but it does strip them. So if your argument is that we 
must do what the C getopt does, then we must likewise at least strip 
trailing spaces.

Attached is a demo, adapted from the code given by `man 3 getopt`.

[steve@ando ~]$ gcc getopdemo.c
[steve@ando ~]$ ./a.out "--  spam" 1 --eggs 2 "--  cheese" 3
option   spam   with arg 1
option eggs   with arg 2
option   cheese with arg 3

If Serhiy is going to insist that getopt.py must follow the C getopt 
precisely, then the failure to strip trailing spaces is certainly a bug.
Files
File name Uploaded
getopdemo.c steven.daprano, 2016-07-26.17:06:27
History
Date User Action Args
2016-07-26 17:06:27steven.dapranosetrecipients: + steven.daprano, r.david.murray, berker.peksag, serhiy.storchaka
2016-07-26 17:06:27steven.dapranolinkissue27619 messages
2016-07-26 17:06:27steven.dapranocreate