Required options in optparse

  • Thread starter Gregory (Grisha) Trubetskoy
  • Start date
G

Gregory (Grisha) Trubetskoy

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top