Created
May 28, 2018 14:52
-
-
Save desh2608/de5a55a424520725bff4ca43ce9fa626 to your computer and use it in GitHub Desktop.
Example of parsing command line arguments in Python
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='Process some integers.') | |
parser.add_argument('integers', metavar='N', type=int, nargs='+', | |
help='an integer for the accumulator') | |
parser.add_argument('--sum', dest='accumulate', action='store_const', | |
const=sum, default=max, | |
help='sum the integers (default: find the max)') | |
args = parser.parse_args() | |
print(args.accumulate(args.integers)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment