#!/usr/bin/python3 # from: https://www.tutorialspoint.com/python/python_command_line_arguments.htm import sys, getopt def main(argv): my_prog='getopts.py' inputfile = '' outputfile = '' helptxt = my_prog+' parameter required: [-i][--ifile] [-o][--ofile] for this help:[-h][--help] ' try: # short opt : and long opt = means required opts, args = getopt.getopt(argv,"hi:o:",["help","ifile=","ofile="]) except getopt.GetoptError: print ('error: ',helptxt) sys.exit(2) for opt, arg in opts: if opt in ('-h','--help'): print (helptxt) sys.exit() elif opt in ('-i', '--ifile'): inputfile = arg elif opt in ('-o', '--ofile'): outputfile = arg # main print ('Input file is ', inputfile) print ('Output file is ', outputfile) # end main if __name__ == "__main__": main(sys.argv[1:])