下面的代码作用是修改文件的编码格式。代码很简单,但是也很牛逼(在我看来),这是在segment上找到的解决办法,废话不多说,直接上代码。
import codecs
def ReadFile(filePath, encoding):
with codecs.open(filePath, "r", encoding=encoding) as f:
return f.read()
def WriteFile(filePath, content, encoding):
with codecs.open(filePath, "w", encoding=encoding) as f:
f.write(content)
def UTF8_to_GBK(src, dst):
content = ReadFile(src, encoding="gbk")
WriteFile(dst, content, "utf-8")