1
我試圖收集從文件的錯誤,我需要指望他們 這是輸出我需要:[ERROR1:6,誤差2:3,誤差3:2]錯誤:unhashable類型=「清單」
import os,sys
import collections
Data = []
errors = []
with open('out.txt') as f:
for line in f:
Data.append([word for word in line.strip().split("\t")])
for item in Data:
try:
date,error = item[0],item[5]
errors.append(error.split('\n'))
except IndexError:
print "A line in the file doesn't have enough entries."
counter = collections.Counter(errors)
print counter
我想你想'errors.extend(..)'而不是'errors.append(..)'。 –