问题 | UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 29解决办法

    xiaoxiao2022-07-05  215

    github:https://github.com/MichaelBeechan :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 pretreatment for 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

    按照上述修改可以使得程序成功运行

    最新回复(0)