0
我想在使用getopt的Python命令行中傳遞兩個參數。我的代碼是:如何在命令行中使用getopt傳遞參數
import sys, getopt
def main(argv):
dataset = ''
build = ''
try:
opts, args = getopt.getopt(argv,"hd:b:",["dataset=","build="])
except getopt.GetoptError:
print 'performance_test.py -d <dataset> -b <build>'
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print 'performance_test.py -d <dataset> -b <build>'
sys.exit()
elif opt in ("-d", "--dataset"):
inputfile = arg
elif opt in ("-b", "--build"):
outputfile = arg
print 'Dataset is "', dataset
print 'Build version is "', build
if __name__ == "__main__":
main(sys.argv[1:])
基本上我傳遞兩個參數中的命令行:(1)數據集(2)構建,但它不是在末尾打印。有人可以幫忙嗎?
非常感謝,我現在看到了這個問題。 –