I am new to python and really confused about this encoding stuff. So far, I've read about the following types of "encoding":
import sys
import locale
print (sys.stdout.encoding)
print (locale.getpreferredencoding())
print (sys.getdefaultencoding())
output:
utf8
cp1252
utf-8
What is the difference?
Simply put, encoding is way your data is stored inside memory.The different ways, allow for more characters, and information. For an in-depth explanation you are more than welcome to read either http://kunststube.net/encoding/, or Wikipedia
In python you can change the way things are stored by either physically calling an encoding type, or with the use of any of the coding function.
For your environment of python3.x, there is no difference between
sys.stdout.encoding
andsys.getdefaultencoding()
. They both use the 8-bite code units (most standard). While the preferred encoding,locale.getpreferredencoding()
(cp1252
), is the windows version oflatin1
.Note that if you would like to get quick feedback with any method/function, you can always use the help command.
Example:
Output: