xxxxxxxxxx
string = "Hello World"
encoded_string = string.encode("utf-8")
print(encoded_string)
xxxxxxxxxx
# insert in the first line of the file
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# or
#!/usr/bin/env python
# -*- coding: utf-8 -*-
xxxxxxxxxx
import codecs # Python standard library
codecs.encode("A strange character","utf-8")
# this would give you the utf-8 encoded bytes
xxxxxxxxxx
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'))