3

I ran few commands like recode and iconv but none worked. I think doing this task via Python will surely help.

What should be the appropriate approach?

aviral sanjay
  • 953
  • 2
  • 14
  • 31

2 Answers2

3

import the libraries

import codecs
import shutil

with codecs.open("inputfile.csv", encoding="utf-16") as input_file:
with codecs.open(
        "outputfile.csv", "w", encoding="utf-8") as output_file:
    shutil.copyfileobj(input_file, output_file)

NB: make sure to read the file with the correct encoding in this case utf-16 as specified in the question and then write it to an output file using the utf-8 encoding sequence.

Pikamander2
  • 7,332
  • 3
  • 48
  • 69
IBRAHIM ALI MUSAH
  • 831
  • 10
  • 19
1
import codecs
import shutil

with codecs.open("input_file.utf8.csv", encoding="utf-8") as input_file:
    with codecs.open(
            "output_file.utf16.csv", "w", encoding="utf-16") as output_file:
        shutil.copyfileobj(input_file, output_file)
Ori Arbes
  • 303
  • 3
  • 13