How To Convert Utf-16 File To Utf-8 In Python

Source URL: https://stackoverflow.com/questions/8827419/convert-utf-16-to-utf-8-and-remove-bom

Language: python

Created on: 2021-01-01 16:34:32

with open(ff_name, 'rb') as source_file:
  with open(target_file_name, 'w+b') as dest_file:
    contents = source_file.read()
    dest_file.write(contents.decode('utf-16').encode('utf-8'))
We have a data entry person who encoded in UTF-16 on Windows and would like to have utf-8 and remove the BOM. The utf-8 conversion works but BOM is still there. How would I remove this? This is wha...
content_copy