python arguments example

程式筆記 因為很弱所以要做筆記 XD

#!/usr/bin/env /usr/bin/python2

import getopt, sys

argumentList = sys.argv[1:]
options = "h:p:"
long_options = ["hdf5=", "plot="]

try:
    arguments, values = getopt.getopt(argumentList, options, long_options)

    if len(sys.argv) == 1:
       print (("%s --hdf5=xxx --plot=xxx") % sys.argv[0])
       exit()
    for currentArgument, currentValue in arguments:
        if currentArgument in ("-h", "--hdf5"):
            print (("hdf5 (%s)") % (currentValue))
        elif currentArgument in ("-p", "--plot"):
            print (("plot (%s)") % (currentValue))

except getopt.error as err:
    print (str(err))

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.