getopt with negative numbers?

J. Clifford Dyer jcd at sdf.lonestar.org
Thu Sep 27 20:21:46 CEST 2007


If you can access the argument list manually, you could scan it for a negative integer, and then insert a '--' argument before that, if needed, before passing it to getopt/optparse.  Then you wouldn't have to worry about it on the command line. 

Cheers,
Cliff

On Thu, Sep 27, 2007 at 08:08:05PM +0200, Peter Otten wrote regarding Re: getopt with negative numbers?:
> 
> Casey wrote:
> 
> > On Sep 27, 1:34 pm, Peter Otten <__pete... at web.de> wrote:
> >> optparse can handle options with a negative int value; "--" can be used
> >> to signal that no more options will follow:
> > 
> > Thanks, Peter.  getopt supports the POSIX "--" end of options indicator
> > as well, but that seems a little less elegant than being able to simply
> > set a value that tells the parser "I don't use any numeric values as
> > options, and I want to allow negative values as arguments".  At the
> > parser level implemening this would be trivial and I frankly was hoping
> > it had been implemented and it just wasn't mentioned in the spares
> > Python getopt library reference.
> 
> After a quick glance into the getopt and optparse modules I fear that both
> hardcode the "if it starts with '-' it must be an option" behaviour.
> 
> Peter
> -- 
> http://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list