UnicodeEncodeError:"charmap"编解码器无法将字符映射编码为<undefined>



我在用unicode写入文件时遇到问题。我使用的是python 2.7.3。它给了我这样一个错误:

UnicodeEncodeError: 'charmap' codec can't encode character u'u2019' in position 1006: character maps to <undefined>

以下是我的代码示例:错误出现在第f3.write(text)行

f = codecs.open("PopupMessages.strings", encoding='utf-16')
text = f.read()
print text
f.close()
f3 = codecs.open("3.txt", encoding='utf-16', mode='w')
f3.write(text)
f3.close()

我也试着使用"utf-8"one_answers"utf-8-sig",但这对我没有帮助。我在源文件中有这样的符号要读取:['\",;?*&$#@%]和不同语言的符号。我该如何解决这个问题?请帮忙,我先读了stackoverflow的信息,但它对我没有帮助。

删除此行:

print text

并且它应该工作

最新更新