Interleaved commands and options with optparse?

Jack Diederich jack at performancedrivers.com
Wed Jan 22 22:59:34 EST 2003


On Thu, Jan 23, 2003 at 02:33:06AM +0000, 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
> 
> I'd like the semantics of the options to depend on where they are
> placed, e.g. before or after a command etc. (I might have global and
> command-specific switches with the same single-letter abbreviation but
> with different meanings -- as in cvs.)

a quick work-around (or patch!) would split the string on spaces,
and look for the first part that didn't start with a '-'.
Put the first set of parts through the options parser.

Rinse, and repeat.

-jackdied






More information about the Python-list mailing list