getopt with negative numbers?

Casey Caseyweb at gmail.com
Fri Sep 28 13:03:56 EDT 2007


On Sep 27, 10:47 pm, Ben Finney <bignose+hates-s... at benfinney.id.au>
wrote:
> I believe they shouldn't because the established interface is that a
> hyphen always introduced an option unless (for those programs that
> support it) a '--' option is used, as discussed.
Not "THE" established interface; "AN" established interface.  There
are other established interfaces that have different behaviors. I'm a
pragmatist; I write software for users, not techies.  I suspect most
users would expect a command like "abc -a -921 351 175" to treat the
"-921" as a negative integer and not abort the program with some
obscure error about option 921 not being known.
>
> > But I think it is a simple and clever hack and still allows getopt
> > or optparse to function normally.
>
> Except that they *don't* function normally under that hack; they
> function in a way contradictory to the normal way.
Again, it depends on who is defining "normal" and what they are basing
it on. I suspect many (probably most) users who are familiar with
command line input are unaware of the "--" switch which was mainly
designed to support arbitrary arguments that might have an initial
hyphen, a much broader problem than supporting negative values.  I'm
not asking that the default behavior of getopt or optparse change;
only that they provide an option to support this behavior for those of
us who find it useful. Software libraries should be tools that support
the needs of the developer, not rigid enforcers of arbitrary rules.




More information about the Python-list mailing list