当我试图将我的unicode列表写入csv文件时,我得到了AttributeError: 'tuple' object has no attribute 'encode'"
:
with open('assignmentTest.csv', 'wb') as finale:
writer = csv.writer(finale) #creates csv file to write final lists into
finalRows = zip(firstName, lastName, phdName, universityName, departmentName) #put all of the lists into another lists so that the outputs are in 'column form' as opposed to rows
for rowToken in finalRows: #puts each element of each list together in the same order
conver = rowToken
writer.writerow(conver.encode('utf-8'))
最初(没有.encode('utf-8'))我收到错误:
^{pr2}$有人知道如何解决这个问题,这样我就可以写我的单子了吗?在
只能对字符串进行编码(具体地说,Unicode字符串到字节字符串)。在
^{1}$rowToken
不是字符串,而是字符串列表。你必须单独编码里面的每个字符串。例如:相关问题 更多 >
编程相关推荐