我怎麼沒看到"Too many values to unpack" Exception適用於我的問題,如果它不請解釋蟒蛇誤差值過多解壓
回溯:
c:\***>python graphJSON.py
Traceback (most recent call last):
File "graphJSON.py", line 17, in <module>
for region, four, one, two, three, threep in rows:
ValueError: too many values to unpack
我遇到這個值過多錯誤簡單的代碼並不能確定問題是什麼:錯誤來自for循環。我收到一條消息說,之前已經有人問過這個問題,答案完全不清楚!
rows = csv.reader(open("graph.csv", "rb"))
# Init the the lists that will store our data
regions = []
fourHrs = []
oneDay = []
twoDay = []
threeDay = []
plusThreeDay = []
# Iterate through all the rows in our CSV
for region, four, one, two, three, threep in rows:
regions = regions + [region]
fourHrs = fourHrs + [four]
oneDay = oneDay + [one]
twoDay = twoDay + [two]
threeDay = threeDay + [three]
plusThreeDay = plusThreeDay + [threep]
# Format the output
output = {"data":[{"Regions":regions},
{"Four Hours":fourHrs},
{"One Day":oneDay},
{"Two Days":twoDay},
{"Three Days":threeDay},
{"More than Three Days":plusThreeDay}
]}
生成JSON文件 json_file =打開( 「graph.json」, 「W」) 傳入json.dump(輸出,json_file) 數據在CSV樣子:
First 28 25 10 2 7
Second 51 17 8 5 15
Third 38 33 24 7 19
已回答:事實證明問題出在CSV上,它刪除了一個階段的更多列,但是,我認爲在Excel中,參考不會被完全刪除。所以,從重做的CSV從它的工作!
你應該粘貼確切的回溯。 – djc
'rows'是整個文件的迭代器。您試圖將所有行解壓縮,每個都放入1個變量中。你有太多的行要做,而不是你想要做的。 – geoffspear
Wooble,這不可能是問題,因爲我之前解包的數量遠遠超過此數 –