getopt: where's da dicts?????

Greg Ewing greg.ewing at compaq.com
Thu Oct 28 03:46:10 EDT 1999


For a while now, when programming in C/C++, I've been using
an argument parser written by an acquaintance some years
ago, that has an API I rather like. You call it thus:

   scanargs(switches, flags)

where switches and flags are sets of characters. The
flags are options which take an argument, and the
switches are ones that don't.

After that, you find out how many times option c occurred 
using

   argcount(c)

and, if it is a flag, the argument associated with
the i'th occurrence using

   argstring(c, i)

It's reasonably flexible. You can use argcount(c)
where c is a switch to find out how many times it
was repeated, and the ordering of multiple occurrences
of an option with an argument is preserved. The
only thing you can't tell is the relative ordering
of different options.

Implementing a Python version of this is left as a
trivial exercise for the reader.

Greg




More information about the Python-list mailing list