Interleaved commands and options with optparse?

Magnus Lie Hetland mlh at
Thu Jan 23 03:49:28 CET 2003

In article <slrnb2ul32.b0e.mlh at>, Magnus Lie Hetland wrote:
>I really love Optik/optparse -- it's a dream to use compared to
>getopt, IMO. Hooray!
>Now... I'd like to interleave "commands" (i.e. simple arguments) with
>my options, as in, e.g., cvs (or distutils, for that matter). For
>  python --globaloption command --commandoption

It seems that one way of doing this sort of thing would be to
use callbacks for the options, and to inspect parser.largs to see if
it contains the relevant command (probably checking the value of
parser.largs[-1]). Would that be the most straightforward approach
here? (It would seem useful to have some sort of callback support for
the commands themselves, though -- what if I use a command with no
options? Hm.)

Magnus Lie Hetland

More information about the Python-list mailing list