Skip to content

Instantly share code, notes, and snippets.

@desh2608
Created May 28, 2018 14:52
Show Gist options
  • Save desh2608/de5a55a424520725bff4ca43ce9fa626 to your computer and use it in GitHub Desktop.
Save desh2608/de5a55a424520725bff4ca43ce9fa626 to your computer and use it in GitHub Desktop.
Example of parsing command line arguments in Python
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