Created
September 3, 2011 17:42
-
-
Save flavianmissi/1191515 to your computer and use it in GitHub Desktop.
Parsing command-line options
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
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