Skip to content

Instantly share code, notes, and snippets.

@leongkui
Last active May 28, 2025 03:28
Show Gist options
  • Save leongkui/bfa7cd53a55bff83503d5d1cbdd193be to your computer and use it in GitHub Desktop.
Save leongkui/bfa7cd53a55bff83503d5d1cbdd193be to your computer and use it in GitHub Desktop.
Fix/convert GBK/GB2312 format to UTF8
import codecs
import sys
# https://stackoverflow.com/questions/53954604/python-encoding-chinese-to-special-character
infile = codecs.open(sys.argv[1], "r", "gb2312")
lines = infile.readline()
infile.close()
print(lines)
outfile = codecs.open("out.txt", "wb", "utf-8")
outfile.writelines(lines)
outfile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment