您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

UnicodeDecodeError:“ utf8”编解码器无法解码字节0x9c

UnicodeDecodeError:“ utf8”编解码器无法解码字节0x9c

http://docs.python.org/howto/unicode.html#the-unicode- type

str = unicode(str, errors='replace')

要么

str = unicode(str, errors='ignore')

这将删除(忽略)有问题的字符,并返回不包含这些字符的字符串。

对我而言,这是理想的情况,因为我将其用作针对非ASCII输入的保护,这是我的应用程序所不允许的。

使用codecs模块中的open方法读取文件

import codecs
with codecs.open(file_name, 'r', encoding='utf-8',
                 errors='ignore') as fdata:
其他 2022/1/1 18:20:53 有492人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶