当前位置 : 主页 > 编程语言 > python >

python中\u编码

来源:互联网 收集:自由互联 发布时间:2022-06-21
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%8

python中\u编码_数据

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'))


网友评论