0
encoding error
i have a encoding error wen i write in a file cause of a single unicode character '\x9' in a string : >>[...] >>var = "\x9" >>file.write(var+'\n') >>UnicodeError : can't encode ascii it's look like that I'm on pc
2 Respostas
+ 2
Because bytes and characters are different entities.
http://blog.notdot.net/2010/07/Getting-unicode-right-in-JUMP_LINK__&&__Python__&&__JUMP_LINK
TL;DR: Don't use setdefaultencoding(); fix your failure to handle text correctly.
In: "The correct solution is to fix your code so that you handle text correctly." ...
- Use encode() on the byte string and specify the encoding...because it's going to the outside world.
-Optionally prefix the string literal with u (unicode).
Note: I couldn't immediately get Python 2.x or 3.x to accept var="\x9" so I didn't verify.
0
i have a table variable how look like this f=["lol","l\x9l","mdr"] but a unicode string look like this "u' lel" so if i try encode() i will get the same error
I've add my program here : Non working file writer