前提・実現したいこと
自然言語処理の練習をするため、下記のサイトにあるファイルを読み込み、MeCabによる処理をしたいです。
https://www.aozora.gr.jp/cards/000296/card47061.html
ここのテキストファイル(ZIP)をダウンロードしています。
OSはMacを使っています。
原因と対処方法を教えていただけますと幸いです。
発生している問題・エラーメッセージ
UnicodeDecodeError Traceback (most recent call last) <ipython-input-29-95f53f514a7a> in <module> 1 with open('gakumonno_susume.txt', 'r', encoding = 'utf-8') as file: ----> 2 lines = file.readlines() ~/anaconda3/lib/python3.6/codecs.py in decode(self, input, final) 319 # decode input (taking the buffer into account) 320 data = self.buffer + input --> 321 (result, consumed) = self._buffer_decode(data, self.errors, final) 322 # keep undecoded input until the next call 323 self.buffer = data[consumed:] UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8a in position 0: invalid start byte
該当のソースコード
Python3
1with open('gakumonno_susume.txt', 'r', encoding = 'utf-8') as file: 2 lines = file.readlines()
フルパスを指定した場合のコード
Python3
1with open('/Users/username/Downloads/自然言語処理/gakumonno_susume.txt', 'r', encoding = 'utf-8') as file: 2 lines = file.readlines()
エラーメッセージ
UnicodeDecodeError Traceback (most recent call last) <ipython-input-31-4af16d10178e> in <module> 1 with open('/Users/username/Downloads/自然言語処理/gakumonno_susume.txt', 'r', encoding = 'utf-8') as file: ----> 2 lines = file.readlines() ~/anaconda3/lib/python3.6/codecs.py in decode(self, input, final) 319 # decode input (taking the buffer into account) 320 data = self.buffer + input --> 321 (result, consumed) = self._buffer_decode(data, self.errors, final) 322 # keep undecoded input until the next call 323 self.buffer = data[consumed:] UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8a in position 0: invalid start byte
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/08 00:36
2019/06/08 00:38
2019/06/08 00:44
2019/06/08 00:46