Last active
September 9, 2015 00:06
-
-
Save ishu3101/86b9526bfcbc37220b17 to your computer and use it in GitHub Desktop.
Read Command Line arguments using arg parse in Python
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
#! /usr/bin/python | |
import argparse | |
parser = argparse.ArgumentParser(description="This is a test.") | |
parser.add_argument("-e", "--echo", | |
help="echo the string you use here", required = True) | |
parser.add_argument("-u", "--uppercase", | |
help="Echo data to uppercase", action="store_true") | |
parser.add_argument("-v", "--version", action='version', version='%(prog)s 1.0') | |
args = parser.parse_args() | |
print "args.uppercase=%s" % args.uppercase | |
if args.uppercase: | |
print args.echo.upper() | |
else : | |
print args.echo |
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
usage: read_arguments.py [-h] -e ECHO [-u] [--version] | |
This is a test. | |
optional arguments: | |
-h, --help show this help message and exit | |
-e ECHO, --echo ECHO echo the string you use here | |
-u, --uppercase Echo data to uppercase | |
-v, --version show program's version number and exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment