使用codecs模块将UTF-8格式转换成gbk格式

#coding:utf-8

import os
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="utf-8")
    WriteFile(dst, content, "gbk")

 

posted @ 2020-05-13 18:41  隐士无双  阅读(322)  评论(0)    收藏  举报