Interleaved commands and options with optparse?

Magnus Lie Hetland mlh at furu.idi.ntnu.no
Thu Jan 23 03:49:28 CET 2003


In article <slrnb2ul32.b0e.mlh at furu.idi.ntnu.no>, 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
>example:
>
>  python myscript.py --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
http://hetland.org




More information about the Python-list mailing list