Python base64.b64encode生成的字节字符串去掉前边的b
匿名 · 更新于 2018/3/30
mystr = '人生苦短,py是岸' mystr = base64.b64encode(mystr.encode('utf-8')) print(mystr)
输出结果:b'5Lq655Sf6Ium55+t77yMcHnmmK/lsrg='
现在我们要获取纯字符串,也就是不要b,那么如下这样写,也就是b64encode后用decode('ascii')解码一下
mystr = '人生苦短,py是岸' mystr = base64.b64encode(mystr.encode('utf-8')).decode('ascii') print(mystr)
输出结果:5Lq655Sf6Ium55+t77yMcHnmmK/lsrg=
