How to handle two-level option processing with optparse

R. Bernstein rocky at panix.com
Thu Jan 26 06:09:24 CET 2006


optparse is way cool, far superior and cleaner than other options
processing libraries I've used.

In the next release of the Python debugger revision, I'd like to add
debugger options: --help and POSIX-shell style line trace (similar to
"set -x") being two of the obvious ones.

So I'm wondering how to arrange optparse to handle its options, but
not touch the script's options.

For example the invocation may be something like:
  pdb --debugger-opt1 --debugger-opt2 ... debugged-script -opt1 opt2 ...

If a --help option is given to the script to be debugged, I want to
make sure it is not confused for the debugger's help option. 

One simple rule for determining who gets whoit is that options that
come after the script name don't get touched in debugger's option
processing.

Another convention that has been used such as in the X11 "startx"
command is to use "--" to separate the two sets of options. However
this isn't as desirable as the simple rule mentioned above; it would
make entering "--" *all* the time when perhaps most of the time there
are no debugger options (as is the case now).

In other systems you can back an indication of the first option that
hasn't been processed and the remaining options are not touched.

It seems that with all of the flexibility of optparse it should handle
this. I'm not sure right now what the best way to do so would be
though. Suggestions? 



More information about the Python-list mailing list