【发布时间】:2015-08-20 10:31:06
【问题描述】:
如何用空格替换无法使用utf8解码的字符?
# -*- coding: utf-8 -*-
print unicode('\x97', errors='ignore') # print out nothing
print unicode('ABC\x97abc', errors='ignore') # print out ABCabc
如何打印出ABC abc 而不是ABCabc?请注意,\x97 只是一个示例字符。无法解码的字符是未知输入。
- 如果我们使用
errors='ignore',它不会打印任何内容。 - 如果我们使用
errors='replace',它将用一些特殊字符替换那个字符。
【问题讨论】: