I am not sure if it’s with the encoding itself however this is my problem;
JavaScript
x
7
1
import csv
2
3
with open('vocabulary.csv', 'r') as csv_file:
4
csv_reader = csv.reader(csv_file)
5
for line in csv_reader:
6
print(line)
7
I would expect it to print this:
However it does not recognise any of the Japanese characters and rather comes up with
JavaScript
1
9
1
['1', 'x1b$B0l$Dx1b(B', 'x1b$B$R$H$Dx1b(B', 'one']
2
['2', 'x1b$BFs$Dx1b(B', 'x1b$B$U$?$Dx1b(B', 'two']
3
['3', 'x1b$B1_x1b(B', 'x1b$B$($sx1b(B', 'yen']
4
['4', 'x1b$B6bx1b(B', 'x1b$B$+$Mx1b(B', 'money']
5
['5', 'x1b$B$3$lx1b(B', 'x1b$B$3$lx1b(B', 'this']
6
['6', 'x1b$B?eMKF|x1b(B', 'x1b$B$9$$$h$&$Sx1b(B', 'Wednesday']
7
['7', 'x1b$B$"$lx1b(B', 'x1b$B$"$lx1b(B', 'that']
8
['8', 'x1b$B@hx1b(B', 'x1b$B$5$-x1b(B', 'ahead']
9
The encoding I used on the csv file was ISO2022. My question is, is there a way to make this appear properly?
Advertisement
Answer
JavaScript
1
2
1
file = open('vocabulary.csv', 'r', encoding='ISO2022')
2
or try
JavaScript
1
2
1
line.decode('ISO-2022-JP')
2