TypeError:需要类似字节的对象,而不是' str':错误获取

时间:2017-04-27 12:07:28

标签: python python-3.x pandas

我尝试编写输出文件但得到以下错误:

  

TypeError:需要类似字节的对象,而不是' str'

任何人都可以建议我吗?

import csv

fin = open('another_summary_table.csv')
words = ["PCB","Switch","Socket","Red-Green LED","Solar Panel","Battery", "Load wire"]
found = {}

wr = csv.writer(open("boop-1.csv", "wb"))
fieldnames = ['PartsReplaced']
writer = csv.DictWriter(fin, fieldnames=fieldnames)
for line in fin:
    split_line=line.split(',')
    str1=split_line[2] # Whatever columns
    PartsReplaced=split_line[2] # Whatever columns

    for w in words:
        if w in str1:
            found[w]=found.get(w,0)+1

            break
wr.writerows(found)

0 个答案:

没有答案