Item 3: Know the difference between bytes, str, unicode (p5 ~ p7)
** In python, if you don't understand string processing, you will fall into a pitfall. ** **
In particular
--In python2, the strings are str and unicode
--In python3, the strings are str and bytes --str and bytes cannot be used together in operators --str defaults to unicode (although you can use u'' separately ...) --encode from str to bytes --bytes to str is decode
** Common pitfalls ** --In python2, when handling ASCII (7bit), if it is within the range of ASCII characters, it works without specifying str or unicode, but if it exceeds that range, the character code gets lost and an exception occurs. --In python3, the processing related to file operations is set to UTF-8 by default. An error occurs when trying to write binary data (which seems to be the point where python2 people stumble). It is better to set it to'wb'(binary writing) instead of'w' in encoding.
Recommended Posts