Code
# -*- coding: ISO-8859-15 -*-
import sys
import codecs
filename2 = "log_unicode2.log"
log_file2 = codecs.open(filename2, "w", "utf-8")
sys.stdout = log_file2
log_file2.write('aééé')
Error
Traceback (most recent call last):
File "snippet_problem_unicode.py", line 7, in <module>
log_file2.write('a├®├®├®')
File "C:\Users\dev1\Envs\atao\lib\codecs.py", line 691, in write
return self.writer.write(data)
File "C:\Users\dev1\Envs\atao\lib\codecs.py", line 351, in write
data, consumed = self.encode(object, self.errors)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1: ordinal
not in range(128)
Contexte
- Windows 7
- Python 2.6
- Eclipse
'aééé' is a byte string (latin-1) which need to be converted to utf-8. Why do this conversion involve ascii codec ?