我正在尝试在 python 中解码 u'\uf04a' 因此我可以打印它而不会出现错误警告。换句话说,我需要将愚蠢的微软 Windows 1252 字符转换为实际的 unicode
包含异常错误的 html 来源来自这里http://members.lovingfromadistance.com/showthread.php?12338-HAVING-SECOND-THOUGHTS
单击此处阅读有关 u'\uf04a' 和 u'\uf04c' 的信息http://www.fileformat.info/info/unicode/char/f04a/index.htm
一个示例如下所示:
"Oh god please some advice ":
Out[408]: u'天哪,请给点建议 \uf04c'
给定一个像这样的线程作为测试的一个例子:
thread = u'who are you \uf04a Why you are so harsh to her \uf04c'
thread.decode('utf8')
print u'\uf04a'
print u'\uf04a'.decode('utf8') # error!!!
'charmap' 编解码器无法对位置 1526 中的字符 u'\uf04a' 进行编码:字符映射到未定义
在两个 Python 脚本的帮助下,我成功转换了 u'\x92',但我仍然卡在 u'\uf04a' 上。有什么建议么?
参考
https://github.com/AnthonyBRoberts/NNS/blob/master/tools/killgremlins.py
使用 Python 处理 CSV 中的非标准美式英语字符和符号
解决方案:
根据下面的评论:我用问号('?')替换这些字符集
thread = u'who are you \uf04a Why you are so harsh to her \uf04c'
thread = thread.replace(u'\uf04a', '?')
thread = thread.replace(u'\uf04c', '?')
希望这对其他初学者有所帮助。