Looking for for some ideas for argument processing

Gordon McMillan gmcm at hypernet.com
Sat Jun 5 23:14:52 EDT 1999


Chuck <cmedcoff at my-deja.com> writes:

> I'm writing a script with is going to make heavy use of script
> arguments.  I'd like to hear some ideas on some ways to support
> this.
> 
> One idea I've had so far is to write a class which is a dictionary
> of "directives" to function objects, where a "directive" might be '-
> c', '/f', or whatever.  This seems to work well if all arguments are
> of this simple form.  However I would also like to support arguments
> like "python myscript.py /a /f /x "bip" "bop", /g"; the point here
> being that "directives" may take arguments.  This kind of messes up
> the simple loop you'd otherwise use to process arguments.

Try getopts from the standard distribution. If that doesn't fit your 
needs, there's at least one enhanced version in the contrib section 
(follow the links from python.org).

- Gordon




More information about the Python-list mailing list