質問編集履歴

1

フルパスを指定した場合のコードとエラーメッセージを追加しました

2019/06/08 00:43

投稿

J1N
J1N

スコア56

test CHANGED
File without changes
test CHANGED
@@ -65,3 +65,53 @@
65
65
  lines = file.readlines()
66
66
 
67
67
  ```
68
+
69
+
70
+
71
+ ### フルパスを指定した場合のコード
72
+
73
+
74
+
75
+ ```Python3
76
+
77
+ with open('/Users/username/Downloads/自然言語処理/gakumonno_susume.txt', 'r', encoding = 'utf-8') as file:
78
+
79
+ lines = file.readlines()
80
+
81
+ ```
82
+
83
+
84
+
85
+ ### エラーメッセージ
86
+
87
+
88
+
89
+ ```
90
+
91
+ UnicodeDecodeError Traceback (most recent call last)
92
+
93
+ <ipython-input-31-4af16d10178e> in <module>
94
+
95
+ 1 with open('/Users/username/Downloads/自然言語処理/gakumonno_susume.txt', 'r', encoding = 'utf-8') as file:
96
+
97
+ ----> 2 lines = file.readlines()
98
+
99
+
100
+
101
+ ~/anaconda3/lib/python3.6/codecs.py in decode(self, input, final)
102
+
103
+ 319 # decode input (taking the buffer into account)
104
+
105
+ 320 data = self.buffer + input
106
+
107
+ --> 321 (result, consumed) = self._buffer_decode(data, self.errors, final)
108
+
109
+ 322 # keep undecoded input until the next call
110
+
111
+ 323 self.buffer = data[consumed:]
112
+
113
+
114
+
115
+ UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8a in position 0: invalid start byte
116
+
117
+ ```