Python编码问题,转换问题

python中的urlencode与urldecode

在Python3中,将中文进行urlencode编码使用函数

urllib.parse.quote(string, safe=’/’, encoding=None, errors=None)
而将编码后的字符串转为中文,则使用

urllib.parse.unquote(string, encoding=‘utf-8’, errors=‘replace’)
示例代码如下:

test = "微信公众账号比特量化"
print(test)
new = urllib.parse.quote(test)
print(new)
print(urllib.parse.unquote(new))

执行结果如下

微信公众账号比特量化
%E5%BE%AE%E4%BF%A1%E5%85%AC%E4%BC%97%E8%B4%A6%E5%8F%B7%E6%AF%94%E7%89%B9%E9%87%8F%E5%8C%96
微信公众账号比特量化

猜你喜欢

转载自blog.csdn.net/SeeUa/article/details/89035585