Skip to content

Instantly share code, notes, and snippets.

@flavianmissi
Created September 3, 2011 17:42
Show Gist options
  • Save flavianmissi/1191515 to your computer and use it in GitHub Desktop.
Save flavianmissi/1191515 to your computer and use it in GitHub Desktop.
Parsing command-line options
from argparse import ArgumentParser
parser = 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)
# python command_line_parser.py --help to usage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment