To convert a single file using Python (as I was asked ...)
import codecs with codecs.open(filename_in, 'r', 'windows-1252') as fin: with codecs.open(filename_out, 'w', 'utf-8') as fout: for line in fin: fout.write(line)
You can also encode utf-8 directly to a string without writing it to a file:
utf8_line = line.encode('utf-8')
source share