I appreciate that this is an old question, but only recently having solved a similar problem, I decided to share my solution.
I had a file that was prepared by one program that I needed to import into the sqlite3 database, but the text file was always "ANSI", and sqlite3 required UTF-8.
ANSI encoding is recognized as "mbcs" in python, and so the code I used breaks something else that I found:
blockSize = 1048576 with codecs.open("your ANSI source file.txt","r",encoding="mbcs") as sourceFile: with codecs.open("Your UTF-8 output file.txt","w",encoding="UTF-8") as targetFile: while True: contents = sourceFile.read(blockSize) if not contents: break targetFile.write(contents)
The link below contains some information about the encoding types that I found in my research
https://docs.python.org/2.4/lib/standard-encodings.html
source share