Python string encodig
String encoding in Python is not entirely straight forward. The usage of encode() and decode() functions is a bit confusing and using them often results in UnicodeEncodeError or UnicodeDecodeError. I couldn’t find any good mnemonics for remembering when each function is supposed to be used so I came up with this word:
decienco
It should be interpreted as; decode() input and encode() output. The other thing to remember is to keep bytes/str on the “outside” of the script and keep strings in unicode internally (default in Python 3, “u” prefix in Python 2).
Now, I’ll just have to remember the word I’ve made up or at least remember that I’ve written this post.
Some useful pages:
A simple explanation of character encoding in Python
Python Central, Encoding and Decoding Python Strings Series