1. utf-8转化gbk
def ReadFile(filePath,encoding="utf-8"): with codecs.open(filePath,"r",encoding) as f: return f.read() def WriteFile(filePath,u,encoding="gbk"): with codecs.open(filePath,"w",encoding) as f: f.write(u) #def WriteFile(filePath,u,encoding="gbk"): # with codecs.open(filePath,"wb") as f: # f.write(u.encode(encoding,errors="ignore")) #def UTF8_2_GBK(src,dst): # content = ReadFile(src,encoding="utf-8") # WriteFile(dst,content,encoding="gbk") def UTF8_2_GBK(src,dst): content = ReadFile(src,encoding="utf-8") WriteFile(dst,content,encoding="gb18030")
时间: 2024-10-31 18:37:23