On Sep 27, 2:21 pm, "J. Clifford Dyer" <[EMAIL PROTECTED]> 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.
>
> Cheers,
> Cliff

Brilliant!

# Look for the first negative number (if any)
for i,arg in enumerate(sys.argv[1:]):
    # stop if a non-argument is detected
    if arg[0] != "-": break
    # if a valid number is found insert a "--" string before it which
    # explicitly flags to getopt the end of options
    try:
        f = float(arg)
        sys.argv.insert(i+1,"--")
        break;
    except ValueError:
        pass

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to