文章内容
2017/9/19 11:24:46,作 者: 黄兵
AttributeError: 'list' object has no attribute 'decode'?
python 2.7 报错:
AttributeError: 'list' object has no attribute 'decode'?
decode和encode是str和unicode才有的方法,list是数据结构,数据结构里没有这个编码的
解决方案:
#coding=gbk
import csv
with open('sina_context.csv','rb') as csvfile:
spamreader = csv.reader(csvfile)
rows=[]
for row in spamreader:
rows.append(row)
rowNumber=len(rows)
for item in range(1,rowNumber):
print rows[item][1].decode('gbk')
参考资料:segmentfault - AttributeError: 'list' object has no attribute 'decode'?
黄兵个人博客原创。
转载请注明出处: 黄兵个人博客 - AttributeError: 'list' object has no attribute 'decode'?
评论列表