UnicodeEncodeError:'gbk'编解码器无法对位置25的字符'\ ue13b'进行编码:非法的多字节序列 [英] UnicodeEncodeError: 'gbk' codec can't encode character '\ue13b' in position 25: illegal multibyte sequence

查看:47
本文介绍了UnicodeEncodeError:'gbk'编解码器无法对位置25的字符'\ ue13b'进行编码:非法的多字节序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误:

 UnicodeEncodeError: 'gbk' codec can't encode character '\ue13b' in position 25: illegal multibyte sequence

文件编码格式为utf-8,读取时文件中有无法识别的单词.‘左足趾麻木’

The file encoding format is utf-8, and there is an unrecognized word in the file when it is read. ‘左足趾麻木’

代码:

for line in open(label_filepath, encoding='utf-8'):
    print(line)

推荐答案

将本机编码更改为utf-8

Change the native encoding to utf-8

import sys
import io
sys.stdout = io.TextIOWrapper(buffer=sys.stdout.buffer,encoding='utf8')

这篇关于UnicodeEncodeError:'gbk'编解码器无法对位置25的字符'\ ue13b'进行编码:非法的多字节序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆