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

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -