Comment 3 for bug 794705

Revision history for this message
Kevin L. Mitchell (klmitch) wrote :

(I hate launchpad. To continue:)

    args = ()
    kwargs = {}
    for arg in argv:
        if '=' in arg:
            k, v = arg.split('=', 1)
            kwargs[k] = v
        else:
            args.append(arg)
    return args, kwargs

Then, in main():

    args, kwargs = parse_args(argv)
    try:
        fn(*args, **kwargs)
        sys.exit(0)
    [...]

There are more subtleties we could try to take account of, too, like either prohibiting non-'=' arguments after encountering '=' arguments, or making such arguments be assigned to the parameters after the key.