Skip to content
Advertisement

text to csv file for japanese characters(Errors in arrangements)

I wanted to convert my text file into csv file, however, my output seems to be very different from what I expected. Below are the examples:

text.txt (Encoding is “UTF-8”)

text =

JavaScript

My code:

JavaScript

Output:

enter image description here

My expected output:

enter image description here

It seems like I am getting quite a lot of ……. for the japanese characters. Could anyone please assist me on this?

Advertisement

Answer

Windows use the BOM to determine encoding of text, but Python does not seem to auto-generate the BOM, and Windows may recognize the output file as ANSI. Try adding out_file.write('ufeff') immediately after the inner with.

Source: Adding BOM (unicode signature) while saving file in python

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement