Looking for for some ideas for argument processing

cmedcoff at my-deja.com cmedcoff at my-deja.com
Sat Jun 5 19:57:34 EDT 1999


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.

        a = BuildArgumentProcessor()

        # process arguments
        for x in sys.argv[1:]:
            opt = x[1:2]
            optArg = x[2:]
            a.Process(opt, optArg)

This would work if somehow inside the for loop one could "increment
this list iterator more that once" (sorry I'm coming from a C++
background).  I don't see anyway of doing this.  Is it possible?  Any
other ideas?

Regards,
Chuck


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




More information about the Python-list mailing list