Created
July 3, 2013 08:12
-
-
Save ff6347/5916265 to your computer and use it in GitHub Desktop.
# usage argparse http://docs.python.org/2/library/argparse.html#module-argparse args parse example
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
# usage argparse http://docs.python.org/2/ | |
# library/argparse.html#module-argparse | |
import argparse | |
parser = argparse.ArgumentParser(prog='ARGS Parse Example') | |
parser.add_argument('--version', action='version', version='%(prog)s 0.1') | |
parser.add_argument('nonoptional', help='a nonoptional argument') | |
parser.add_argument('-o', '--optional', | |
help='this is an optional flag', | |
action="store_true") | |
parser.add_argument("-l", "--log", help="something", | |
action="store_true") | |
parser.add_argument('-s', '--something', nargs='+', help='additional argument') | |
args = parser.parse_args() | |
print args | |
print "nonoptional = ", args.nonoptional | |
print "-o --optional = ", args.optional | |
print "-l --log = ", args.log | |
print "-s --something = ", args.something |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment