http://docs.python.org/howto/unicode.html#the-unicode- type
str = unicode(str, errors='replace')
要么
str = unicode(str, errors='ignore')
这将删除(忽略)有问题的字符,并返回不包含这些字符的字符串。
对我而言,这是理想的情况,因为我将其用作针对非ASCII输入的保护,这是我的应用程序所不允许的。
import codecs
with codecs.open(file_name, 'r', encoding='utf-8',
errors='ignore') as fdata: