实现编码转换
# 直接实现编码转换
import codecs
def ReadFile(filePath,encoding="utf-8"):
with codecs.open(filePath,"r",encoding) as f:
return f.read()
def WriteFile(filePath,content,encoding="gbk"):
with codecs.open(filePath,"w",encoding) as f:
f.write(content)
def UTF8_to_GBK(src,dst):
content = ReadFile(src,encoding="utf-8")
WriteFile(dst,content,encoding="gbk")
def GBK_to_UTF8(src,dst):
content = ReadFile(src,encoding="gbk")
WriteFile(dst,content,encoding="utf-8")
参考: thulac