私はPythonを使用して、以下のセグメントのテキストファイルを読み取っています
(私は初心者なのでスクリーンショットを投稿できません)しかし、これはnotepad++でのように見えます:
NULSOHSOHNULNULNULSUBMesssage-ID:
エラー:
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
print(f.readline())
File "C:\Python32\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 0x8f in position 7673: character maps to <undefined>
ファイルをバイナリとして開く:
f = open('file.txt','rb')
f.readline()
テキストをバイナリとして表示します
b'\ x00 \ x01 \ x01 \ x00 \ x00 \ x00 \ x1a \ xb7Message-ID:
しかし、テキストをASCIIとして取得するにはどうすればよいですか?そして、これを処理する最も簡単な/pythonicな方法は何ですか?