在下面的代碼,我試圖解析命令行參數:Python的選擇採用命令行參數屬性
import sys, getopt
opts, args = getopt.getopt(sys.argv[1:],'hs:c:i:I')
opts = dict(opts)
print opts
print args
if '-s-' in opts:
print opts['-s']
當我運行代碼,我得到:
{}
['python', 'Practice5.py', '-s', 'stop_list.txt', '-c', 'documents.txt', '-i', 'index.txt', '-I']
命令行是:
python Practice5.py -s stop_list.txt -c documents.txt -i index.txt -I
爲什麼opts有空值?
。 {'-I':'','-i':'index.txt','-c':'documents.txt','-s':'stop_list.txt'} [] – balabhi