1、UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0xac in position 43: illegal multibyte sequence
源码:
with open('a.csv', 'r') as f: for line in f.readlines(): print(line)
报错:
UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position 43: illegal multibyte sequence
解决方案:
with open('a.csv', 'r', encoding='utf-8') as f: for line in f.readlines(): print(line)
分析原因:
Unicode的解码错误,打开文件时需要设定解码方式。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)