看板 Python 關於我們 聯絡資訊
f = open("list.txt", "r") count ={} for line in f: line = line.strip('\n') (item, num) = line.split(',') #print "%s --> %s" %(item,num) if count.has_key(item): count[item] = count[item]+int(num) else: count [item] = int(num) split那行會跑出下面這個錯誤 ValueError: need more than 1 value to unpack 原本是在linux上跑的,我在windows打卻不能執行 也不需要輸入甚麼參數阿,我看不懂這邊是哪裡有問題 還請各位幫我看看,謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.127.233.24 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1553585685.A.88E.html ※ 編輯: andrew5106 (140.127.233.24), 03/26/2019 15:40:06 ※ 編輯: andrew5106 (140.127.233.24), 03/26/2019 15:47:12
bcew: 可以在split前印一下line,看什麼字串造成錯誤 03/26 16:44
jackwang01: 可能 line 是空的吧 03/26 18:29
toy9986619: 確認是否有正常讀檔,且 line 有正常的值 03/27 08:46