I forgot about optparse. Looks like the only way to handle this with optparse is with a callback like this .

<pre>from optparse import OptionParser
def cb(option, opt_str, value, parser):
        args=[]
        for arg in parser.rargs:
                if arg[0] != "-":
                        args.append(arg)
                else:
                        del parser.rargs[:len(args)]
                        break
        if getattr(parser.values, option.dest):
                args.extend(getattr(parser.values, option.dest))
        setattr(parser.values, option.dest, args)

parser=OptionParser()
parser.add_option("-q", "--quiet",
        action="store_false", dest="verbose",
        help="be vewwy quiet (I'm hunting wabbits)")
parser.add_option("-f", "--filename",
        action="callback", callback=cb, dest="file")
</pre>

But I couldn't find something similar in argparse. So unless we want to have 2 sets of code adding arguments (1 with callbacks and 1 with nargs) then we're probably better off cleaning it out before passing it to optparse.