# python unicode编码问题

# len函数:

len如果是utf8字符串,则计算的字节长度,汉字一般是3个字段, 如果是unicode编码,则计算的字符个数 python http请求如果对方返回的是utf8格式的数据, 则进入到python代码,会自动转为unicode编码, 可以看到字典字段前带了个u""

# %格式化时,转为unicode

格式化输出时,如果参数有unicode编码,最终输出的也是unicode编码。 len 再计算就是字符个数,而不是字节长度; 准确计算字节数,需要把unicode的字段.encode("utf-8")编码一下,再拼接进去。