Skip to content

Instantly share code, notes, and snippets.

@dvictori
Created July 22, 2019 11:55
Show Gist options
  • Save dvictori/c277aa12d0f7f1bcc5b0c061227f1442 to your computer and use it in GitHub Desktop.
Save dvictori/c277aa12d0f7f1bcc5b0c061227f1442 to your computer and use it in GitHub Desktop.
Get rid of bogus characters in UTF-8 encoding file
#!/usr/bin/env python3
import io
import os, sys
os.rename(sys.argv[1],'tempfile.sql')
saida = open(sys.argv[1], "w")
with io.open("tempfile.sql", encoding="utf-8", errors='ignore') as f:
for line in f:
saida.write(line)
saida.close()
os.remove("tempfile.sql")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment