Created
January 14, 2018 05:52
-
-
Save ipan/19c2ea62ff94407fff7ae07c1f57ba48 to your computer and use it in GitHub Desktop.
quick examples of argparse usage
This file contains 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(description="script description") | |
parser.add_argument('input_names', nargs="*", help="input name(s)") | |
parser.add_argument('-t', '--target', required=True) | |
parser.add_argument('-of', '--option-flag', action='store_true', default=False, help="description for option flag") | |
parser.add_argument('--number', type=int, default=0, help="description for int num") | |
args = parser.parse_args() | |
print("input_names: %r" % args.input_names) | |
print("input_names: %r" % args.target) | |
print("input_names: %r" % args.option_flag) | |
print("input_names: %d" % args.number) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment