Using argparse.REMAINDER at beginning of parser / sub parser
问题 I want to implement an arg parser that allows me to run unittests as one of the sub commands, blindly passing the arguments on to unittest.main(). e.g., $ foo.py unittest [args to pass to unittest.main()] along with other sub commands: $ foo.py foo ... $ foo.py bar ... Following argparse's example, this works: #!/usr/bin/python import argparse p = argparse.ArgumentParser(prog='PROG') p.add_argument('-v', '--verbose', action='store_true') sub = p.add_subparsers(dest='cmd') foo = sub.add_parser