Skip to content

Instantly share code, notes, and snippets.

@ishu3101
Last active September 9, 2015 00:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ishu3101/86b9526bfcbc37220b17 to your computer and use it in GitHub Desktop.
Save ishu3101/86b9526bfcbc37220b17 to your computer and use it in GitHub Desktop.
Read Command Line arguments using arg parse in Python
#! /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
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