Created
August 7, 2020 05:22
-
-
Save ra312/fb6792d9b365c1538d014a6fcd45f965 to your computer and use it in GitHub Desktop.
fix text file encoding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import chardet | |
import codecs | |
infile = 'unreadable.txt' | |
outfile = 'readable.txt' | |
with open(infile,'rb') as raw_file: | |
result = chardet.detect(raw_file) | |
char_enc = result['encoding'] | |
with open(outfile, 'r', charenc): | |
read_as_utf = f.read() | |
out = codecs.open(outfile, 'w', 'utf-8') | |
out.write(read_as_utf) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment