python gbk 相互转换 utf8

简介: python gbk 相互转换 utf8

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("转化完成")
相关文章
|
8天前
|
编解码 Python Windows
Python写入文件报错‘gbk’ codec can’t encode character的解决办法
Python写入文件报错‘gbk’ codec can’t encode character的解决办法
80 2
|
9月前
|
Linux Python Windows
Python | Python学习之unicode和utf8
Python | Python学习之unicode和utf8
|
9月前
|
数据库 Python
python时间格式的相互转换
python时间格式的相互转换
55 0
|
10月前
|
存储 索引 Python
【python】如何将数据在csv和xlsx之间相互转换
【python】如何将数据在csv和xlsx之间相互转换
|
Python
Python Excel表格列数的字母表达与数字的相互转换
Python Excel表格列数的字母表达与数字的相互转换
279 0
|
存储 Shell Python
Python编程中的基础数据类型:文本型、整型、浮点型,以及如何相互转换?【零基础Python教程006】
Python编程中的基础数据类型:文本型、整型、浮点型,以及如何相互转换?【零基础Python教程006】
235 0
|
JSON PHP 数据格式
【python】or【php】网页中字符编码转换,将反斜杠u \u字符串转为unicode/utf8
【python】or【php】网页中字符编码转换,将反斜杠u \u字符串转为unicode/utf8
110 0
|
计算机视觉 Python
【python】python中PIL.Image和OpenCV图像格式相互转换
python中PIL.Image和OpenCV图像格式相互转换
|
Python
Python编程:namedtuple命名元组和dict字典相互转换
Python编程:namedtuple命名元组和dict字典相互转换