回答編集履歴
2
修正
answer
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
filename = "sample.csv"
|
8
8
|
try:
|
9
|
-
with codecs.open(filename, encoding="
|
9
|
+
with codecs.open(filename, encoding="utf-8") as f1:
|
10
10
|
A = f1.readlines()
|
11
11
|
except Exception as e:
|
12
12
|
print("ignore 発生", e)
|
1
修正
answer
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
最初は errors="strict" で読み込んでみて、駄目だったら、errors="ignore" で読み込めば、"ignore" が発生したかどうかわかるのではないでしょうか。
|
2
|
+
エラーが発生した行数も Exception オブジェクトから拾えます。
|
2
3
|
|
3
4
|
```python
|
4
5
|
import codecs
|
5
6
|
|
6
7
|
filename = "sample.csv"
|
7
8
|
try:
|
8
|
-
with codecs.open(filename, encoding="
|
9
|
+
with codecs.open(filename, encoding="ascii") as f1:
|
9
10
|
A = f1.readlines()
|
10
|
-
except:
|
11
|
+
except Exception as e:
|
11
|
-
print("ignore 発生")
|
12
|
+
print("ignore 発生", e)
|
12
13
|
with codecs.open("sample.csv", encoding="utf-8", errors="ignore") as f1:
|
13
14
|
A = f1.readlines()
|
14
15
|
```
|