python 转码出错封装函数

# 那一个字转码出错 就去掉那一个 这下面是用的gbk 如果是UTF-8需要改
def gbk(con):

    while True:

        try:
            
            content = con.encode('gbk').decode('gbk')

            return content
                        
        except Exception as e:

            x = re.findall("er '(.+)' in",str(e))[0]
                            
            #print('程序出错',x)

            con = re.sub(x,'',con)
                

猜你喜欢

转载自blog.csdn.net/AnYeZhiYin/article/details/105433258