Created
February 23, 2017 14:34
-
-
Save bchess/326da50168729e82f5d17d913bef5cc3 to your computer and use it in GitHub Desktop.
argparse parse_known_args()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
parser = argparse.ArgumentParser(add_help=False) | |
parser.add_argument('--env', '-e', action='append') | |
parser.add_argument('--hostname', '-h') | |
known, unknown = parser.parse_known_args(['-e', 'key=value']) | |
print '1. known', known | |
print '1. unknown', unknown | |
assert known.env == ['key=value'] | |
known, unknown = parser.parse_known_args(['-te', 'key=value']) | |
print '2. known', known | |
print '2. unknown', unknown | |
assert known.env == ['key=value'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment