Required options in optparse

Gregory (Grisha) Trubetskoy grisha at modpython.org
Fri Oct 3 21:31:05 EDT 2003


My humble $0.02:

>From http://www.python.org/doc/current/lib/optparse-terminology.html:

  The phrase "required option" is an oxymoron; the presence of
  "required options" in a program is usually a sign of careless user
  interface design. optparse doesn't prevent you from implementing
  required options, but doesn't give you much help with it either.

I don't know if I necessarily agree with this. While "required option" may
be an oxymoron as far as English is concerned, I think a more accurate
assessment is that "option" is a misnomer, because there is nothing wrong
with requiring one.

Here is an example from a fictional database program. Imagine that to
craete a database I have to specify a name, db size and a some kind of a
device id (the two latter both being integers):

usage: initdb dbname -s size -d dev_id [-t dbtype]

e.g.:

$ initdb mydb -s 1024 -d 1010

Arguably, dbname, size and dev_id could be specified as required
positional _arguments_, but it would be less clear and more error-prone:

usage: initdb dbname size dev_id [-t dbname]

e.g.:

$ initdb mydb 1024 1010

Therefore, I think "required options" should be part of OptionParser.

Anyone disagree?

Grisha




More information about the Python-list mailing list