UnicodeDecodeError:'charmap'编解码器无法解码位置7736的字节0x98:字符映射到<undefined>

时间:2019-07-10 09:26:24

标签: python python-3.x unicode character-encoding

UnicodeDecodeError:'charmap'编解码器无法解码位置7736的字节0x98:字符映射到<undefined>

def ReadAllText(path):
    r = open(path.replace("\\x", "%"))
    text = r.read()
    r.close()
    return text

有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

它不能解决问题,但是一种解决方法是将文本文件保存为ANSI编码,然后再次运行脚本。

另一个想法是像这样打开文件:

open(file, errors='ignore')