恶心的字符编码

字符编码
内存默认用unicode-快
磁盘用的utf-8-小

#存储过程中
内存unicode --decode--> utf-8磁盘
utf-8磁盘 --encode--> 内存unicode

#执行过程中
内存unicode --encode--> utf-8(bytes)
utf-8(bytes) --decode--> 内存unicode


python3 所有字符串都是unicode
所以字符串只有 encode方法
*.py 文件头上面 写的是代码保存在硬盘上的,以及读取的字符集

python2中 字符串类型有俩种
str
unicode

str --decode--> utf-8
没有encode
unicode 和python3一样

原文地址:https://www.cnblogs.com/onda/p/6862105.html