Looking for for some ideas for argument processing

Tim Peters tim_one at email.msn.com
Sat Jun 5 23:25:29 EDT 1999


[Chuck <medcoff at my-deja.com>]
> ...
>         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?

Some problems are better approached from a Fortran frame of mind <wink>:

    # process arguments
    i, n = 1, len(sys.argv)
    while i < n:
        x = sys.argv[1:]
        opt = x[1:2]
        # etc; each branch needs to bump i appropriately

Or you could build your own class to fake a multi-increment (or even random
access) iterator:  you'd have a lot of fun, but nobody else would understand
it.

as-much-like-c++-as-you-want<wink>-ly y'rs  - tim






More information about the Python-list mailing list