5
votes

I have a problem with writing to file in unicode. I am using python 2.7.3. It gives me such an error:

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)

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 stackoverflow firstly, but it didn't helped me.

1
What platform are you using (Windows, Mac OS, Linux, ...)? - Roman Susi
I am using Windows 7 x64 - yozhik
I don't think the error is at f3.write(text). I think the error is at print text. wiki.python.org/moin/PrintFails - bobince
Thanks, I just also localized this issue. You right, it's print text problem. - yozhik
You can answer my question and I will accept it, if you want. It's usefull - yozhik

1 Answers

0
votes

delete this line:

print text

and it should work