概念
python使用unicode作为字符串内部编码,所有转换应通过unicode进行
编码(encode),将中间对象(unicode object)转为其他编码对象
解码(decode),将其他编码对象转为中间对象(unicode object)
非unicode object转unicode object
前提必须清楚字符串是什么编码,假设str为gbk编码
u = str.decode('gbk')
或
u = unicode(str, 'gbk')
unicode object转非unicode object
假设转为utf-8
utf8 = u.encode('utf-8')