Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Testing argparse partial parsing
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function, absolute_import, division
def run(options, script_args):
print('options', options, 'script_args', script_args)
if '__main__' == __name__:
import argparse
parser = argparse.ArgumentParser(description="Argparse Test Script")
parser.add_argument("-s", "--steal-output", action="store_true"),
parser.add_argument("-m", "--module", metavar="MODULE",
help="Debug module or package instead of script"),
parser.add_argument("--pre-run", metavar="COMMAND",
help="Run command before each program run",
parser.add_argument('args', nargs=argparse.REMAINDER)
options, script_args = parser.parse_known_args()
run(options, script_args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment