getopt with negative numbers?
ndbecker2 at gmail.com
Fri Sep 28 01:57:03 CEST 2007
> On Sep 27, 2:21 pm, "J. Clifford Dyer" <j... at sdf.lonestar.org> wrote:
>> 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.
> # Look for the first negative number (if any)
> for i,arg in enumerate(sys.argv[1:]):
> # stop if
> if arg != "-": break
> # if a valid number is found insert a "--" string before it
> # explicitly flags to getopt the end of options
> f = float(arg)
> except ValueError:
One person's "brilliant" is another's "kludge".
More information about the Python-list