Python getopt模块
Example: testGetOpt.py
def getArgs(argv=None):
global param1
global param2
global param3
try:
opts, args = getopt.getopt(sys.argv[1:], "x:y:z:",
["name1=", "name2=", "name3="])
except getopt.GetoptError as e:
print (e)
for opt, arg in opts:
if opt == "-x":
name1 = arg
elif opt == "-y":
name2 = arg
elif opt == "-z":
name3 = arg
if __name__ == '__main__' or __name__ == 'main':
print (name1)
print (name2)
print (name3)
testGetOpt.py -x value1 -y value2 -z value3