![](/img/trans.png)
[英]UnicodeEncodeError: 'charmap' codec can't encode character : character maps to <undefined>
[英]UnicodeEncodeError: 'charmap' codec can't encode character character maps to <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'和'utf-8-sig',但它對我沒有幫助。 我的源文件中有這樣的符號:['\\“,;?*&$#@%]和不同語言的符號。如何解決這個問題?請幫忙,我首先閱讀stackoverflow的信息,但它沒幫我
刪除這一行:
print text
它應該工作
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.