【发布时间】:2019-06-01 23:17:52
【问题描述】:
我正在尝试让 Python 3 程序对一个充满信息的文本文件进行一些操作。但是,当尝试读取文件时,出现以下错误:
Traceback (most recent call last):
File "SCRIPT LOCATION", line NUMBER, in <module>
`text = file.read()`
File "C:\Python31\lib\encodings\cp1252.py", line 23, in decode
`return codecs.charmap_decode(input,self.errors,decoding_table)[0]`
UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 2907500: character maps to `<undefined>`
【问题讨论】:
-
对于同样的错误,这些解决方案帮助了我,solution of charmap error
-
请参阅Processing Text Files in Python 3 了解您收到此错误的原因。
-
对于 Python > 3.6,将解释器选项(参数)设置为包含
-Xutf8(应该可以修复它)。
标签: windows python-3.x unicode file-io decode