Skip to content

Instantly share code, notes, and snippets.

@miracleyoo
Created December 19, 2019 19:42
Show Gist options
  • Save miracleyoo/1e1554f3ee062b7973624a495b3d3bf1 to your computer and use it in GitHub Desktop.
Save miracleyoo/1e1554f3ee062b7973624a495b3d3bf1 to your computer and use it in GitHub Desktop.
[Read Write with Right Encoding] #python #file
import chardet
with open(input_path, 'rb') as f:
s = f.read()
chatest = chardet.detect(s)
# print(chatest)
with open(input_path,"r",encoding=chatest["encoding"]) as f:
lines = f.read()
with open(output_path, "w+", encoding=chatest["encoding"]) as fw:
fw.write(lines)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment