本文主要是介绍问题 | UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 29解决办法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
github:https://github.com/MichaelBeechan
CSDN:https://blog.csdn.net/u011344545
python读文件:
file = open(filename, "r") for line in file: #every line is a poem#print(line)title, poem = line.strip().split(":") #get title and poem
出现UnicodeDecodeError:
File "F:\MichaelProject\Chinese_poem\dataPretreatment.py", line 13, in pretreatmentfor line in file: #every line is a poem
UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 29: illegal multibyte sequence
修改:
file = open(filename, "r", encoding='UTF-8')# add encoding='UTF-8'for line in file: #every line is a poem
按照上述修改可以使得程序成功运行
这篇关于问题 | UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 29解决办法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!