I have a problem with writing to file in unicode. I am using python 2.7.3. It gives me such an error:
我有个问题,用unicode写文件。我使用的是python 2.7.3。它给了我这样一个错误:
UnicodeEncodeError: 'charmap' codec can't encode character u'\u2019' in position 1006: character maps to <undefined>
Here is a sample of my code: error is on line: f3.write(text)
下面是我的代码示例:错误在线:f3.write(文本)
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()
I tried to use 'utf-8' and 'utf-8-sig' also, but it doesn't helped me. I have such symbols in my source file to read: ['\",;?*&$#@%] and symbols in different languages. How can I solve this issue? Please help, I read info on * firstly, but it didn't helped me.
我也试着用“utf-8”和“utf-8-sig”,但这对我没有帮助。我的源文件中有这样的符号:['\ ',;?*和$#@%)和不同语言的符号。我该如何解决这个问题?请帮忙,我先看了*的信息,但是没有帮到我。
1 个解决方案
#1
0
delete this line:
删除这条线:
print text
and it should work
它应该工作
#1
0
delete this line:
删除这条线:
print text
and it should work
它应该工作