Skip to content

Instantly share code, notes, and snippets.

@matrix303
Last active July 17, 2019 14:21
Show Gist options
  • Save matrix303/5adf5244d868fc163483621969de11a0 to your computer and use it in GitHub Desktop.
Save matrix303/5adf5244d868fc163483621969de11a0 to your computer and use it in GitHub Desktop.
System Arguments - Terminal File Input #python
# include standard modules
import argparse
# initiate the parser
parser = argparse.ArgumentParser()
parser.add_argument("-V", "--version", help="show program version", action="store_true") #true of false b/c action
parser.add_argument("-W", "--width", help="store width") #no set action = store value
# read arguments from the command line
args = parser.parse_args()
print (args)
# check for --version or -V
if args.version:
print("this is myprogram version 0.1")
if args.width:
print ("this is the width: {}".format(args.width))
#Method 1
import sys
sys.argv[0] = python file
sys.argv[1] = first input parameter after file name, so forth...
#inputed every as string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment