Jython: Getopt does not throw exception - 1 attachments

Emile van Sebille emile at fenx.com
Sat Jun 1 11:32:11 EDT 2002


Joern Bodemann asks:
> does anybody know why the following code does not throw an excetion if
the
> script is started without parameter?
>

The relevant code from getopt (on my version) is:

    while args and args[0].startswith('-') and args[0] != '-':
        [snip]
    return opts, args

which simply drops through to the return because args is empty.

>From your code:

opts, args = getopt.getopt(sys.argv[1:], "s:e:", ["start=", "ende="])

if you intend that  ["start=", "ende="] are required (as the equals
signs indicate), you could do:

opts, args = getopt.getopt(sys.argv[1:3], "s:e:", ["start=", "ende="])

instead, as this will cause an error when called without options.  You
could also check the length or argv.

HTH

--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list