Interleaved commands and options with optparse?

Magnus Lie Hetland mlh at furu.idi.ntnu.no
Wed Jan 22 22:45:50 EST 2003


In article <BA54C839.2F3FE%goodger at python.org>, David Goodger wrote:
[snip]
>Set up an OptionParser instance for the global options, and be sure to set
>the allow_interspersed_args attribute to 0/False.

Ah. Useful. Too bad it isn't mentioned in the docs <0.3 wink>.

(Yes, I see it's in the docstring for OptionParser.)

> Then parse your arglist.
>The global options will be parsed, and the first item of the
>remaining arglist will be your subcommand.  Set up a new OptionParser
>instance for that subcommand, and parse the remainder of the command
>line.

Indeed. Quite useful. This really ought to be in the docs. (If it is,
I apologize -- I went through all the doc pages and searched for it;
and Google only returned one checkin-message from
cheetatemplate-commits and a single message from the optik list...)

Anyway, thanks for the tip!

-- 
Magnus Lie Hetland
http://hetland.org




More information about the Python-list mailing list