Python:file.read()函数错误 - Unicodedecodeerrors



我如何从python中的原始bin文件读取字节,因为file.read.read((函数最终以unicodededecodeerrors?

是特定的,我正在阅读A.bin文件,并且我遇到了此错误。

File "F:CodesPythonMLPybrain_test.py", line 27, in <module>
  string = img_set.read(784)
File "F:ProgramsPythonlibencodingscp1252.py", line 23, in decode
  return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 1440: character maps to <undefined>

如果仅使用open(filename)打开文件,则将其解释为文本,而不是字节。您应该以字节文件打开文件,例如:

f = open(filename, 'b')

,然后f.read()不会给出该错误

最新更新