如何用Python阅读和理解.hcc文件?

2024-06-16 09:37:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个.hcc文件,我正试图读取,但我得到了错误。 这就是我所尝试的:

chardetect 2016.hcc
2016.hcc: windows-1253 with confidence 0.2724130248827703

我尝试了以下方法:

>>> with open("2016.hcc","r",encoding="windows-1253") as f:
...     print(f.read())
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "C:\Python35\lib\encodings\cp1253.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9c in position 232: character maps to <undefined>

然后我尝试了不使用编码的方法:

>>> with open("2016.hcc","r") as f:
...     print(f.read())
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "C:\Python35\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 0x9d in position 284: character maps to <undefined>

在以字节模式打开文件后,我可以阅读,但没有一个是可以理解的。你知道吗

下面是示例文件:2016.hcc

请告诉我怎么做。你知道吗

**更新尝试:**

>>> with open("2016.hcc","r",encoding="utf-16") as f:
...     print(f.read())
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "C:\Python35\lib\codecs.py", line 321, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
  File "C:\Python35\lib\encodings\utf_16.py", line 61, in _buffer_decode
    codecs.utf_16_ex_decode(input, errors, 0, final)
UnicodeDecodeError: 'utf-16-le' codec can't decode bytes in position 15390-15391: illegal encoding

Tags: 文件inpyselflibwithlineutf