python---redis中文操作与系统中文检测

import  redis
import chardet

r.set("name","我是在Py3保存的中文字符串")
ret = r.get("name")#(一个汉字三个字节)
print(ret,type(ret))
print(chardet.detect(ret))#chardet.detect检测的字符串越长越准确,越短越不准确。
print(ret.decode("utf-8"))

在解码Redis返回的字符前要先检测编码方式,根据检测出的编码方式来编码。

chardet.detect检测的字符串越长越准确,越短越不准确

查看于:http://blog.csdn.net/xiemanr/article/details/72793081

posted @ 2018-03-19 23:28  山上有风景  阅读(1158)  评论(0编辑  收藏  举报