Created
September 11, 2013 20:46
-
-
Save dpenfoldbrown/6529549 to your computer and use it in GitHub Desktop.
Argparse argument example
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="Sample usage of argparse") | |
# Add argument. Do not use all elements as shown. Note: for flags, action="store_true" (?syntax?) is better. | |
parser.add_argument("-a", "--first", action="store", type=int, dest="first_arg", required=True, default=23, | |
help="An example first argument. Generally use only one of required or default. Leave out type for default (str).") | |
# Defaults to parsing sys.argv list, but can pass a list as well | |
args = parser.parse_args() | |
# Access args by the 'dest' name as added | |
print "First argument: {0}".format(args.first_arg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment