Python Main Function Command Line Argument Long List -
i'm trying make simple main function caesars shift cryptography program, i'm not quite sure how configure command line opt/arg stuff. want configure program accept command line arguments so:
./caesars.py -e 13 message encrypt
with 13 being amount of shifts , following lines message encrypt. have functions defined, not sure how configure opt arg stuff accept first argument after argv[1] key, after split list/long string. here have far:
def main(): global decoder global encoder if not len(sys.argv[1:]): usage() # read commandline options try: opts, args = getopt.getopt(sys.argv[1:],"hd:e:", ¬ ["help","decode","encode"]) except getopt.getopterror err: print str(err) usage() o,a in opts: if o in ("-h","--help"): usage() elif o in ("-d","--decode"): decode = true elif o in ("-e", "--encode"): encode = true else: assert false,"unhandled option"
thanks in advance.
if haven't already, should docopt. while have never used myself, it's popular , should perfect you.
Comments
Post a Comment