python中\u编码

python中\u编码_第1张图片

from urllib.parse import quote
s=‘images.dmzj.com/m/\u5192\u9669\u738b\u6bd4\u7279/56_1548733081/JOJO_000.png’
s=s.replace(’/’,’/’)
print(’:::’,quote(s))

输出

::: images.dmzj.com/m/%E5%86%92%E9%99%A9%E7%8E%8B%E6%AF%94%E7%89%B9/56_1548733081/JOJO_000.png

from urllib.parse import quote
s=‘images.dmzj.com/m/\u5192\u9669\u738b\u6bd4\u7279/56_1548733081/JOJO_000.png’
s=s.replace(’/’,’/’)
print(’:::’,quote(s))

输出

::: images.dmzj.com/m/%E5%86%92%E9%99%A9%E7%8E%8B%E6%AF%94%E7%89%B9/56_1548733081/JOJO_000.png

从redis中读取的中文数据需要转换指定编码,需要指定utf8

import chardet
import redis

r = redis.Redis(host='127.0.0.1', port=6379)
r.set("wilson93","你好python啊")
r_get = r.get("wilson93")
print(str(r_get))
print(chardet.detect(r_get))
print(str(r_get,encoding='utf8'))

你可能感兴趣的:(实用工具,实用技术)