Last active
July 17, 2019 14:21
-
-
Save matrix303/5adf5244d868fc163483621969de11a0 to your computer and use it in GitHub Desktop.
System Arguments - Terminal File Input #python
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
# 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)) |
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
#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