Skip to content

Instantly share code, notes, and snippets.

@ipan
Created January 14, 2018 05:52
Show Gist options
  • Save ipan/19c2ea62ff94407fff7ae07c1f57ba48 to your computer and use it in GitHub Desktop.
Save ipan/19c2ea62ff94407fff7ae07c1f57ba48 to your computer and use it in GitHub Desktop.
quick examples of argparse usage
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