gbk转utf8
def gbkfileToUtf8(inFilePath,outFilePath): with open(inFilePath, 'rb') as f1: a = f1.read() b = a.decode('gbk', 'ignore') with open(outFilePath, 'w', encoding='utf8') as f2: f2.write(b) print("转化完成")
utf8转gbk
def utf8fileToGbk(inFilePath,outFilePath): with open(inFilePath, 'rb') as f1: a = f1.read() b = a.decode('utf8', 'ignore') with open(outFilePath, 'w', encoding='gbk') as f2: f2.write(b) print("转化完成")