好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

python中base64编码与解码

 

python2中进行Base64编码和解码

>>> import base64
>>> s = ‘我是字符串‘
>>> a = base64.b64encode(s)
>>> print a
ztLKx9fWt/u0rg==
>>> print base64.b64decode(a)
我是字符串

 

python3不太一样:因为3.x中字符都为unicode编码,而b64encode函数的参数为byte类型,所以必须先转码。

import base64
encodestr = base64.b64encode(‘abcr34r344r‘.encode(‘utf-8‘))
print(str(encodestr,‘utf-8‘))
打印结果为 YWJjcjM0cjM0NHI=    参考: https://HdhCmsTestcnblogs测试数据/zanjiahaoge666/p/7242642.html

查看更多关于python中base64编码与解码的详细内容...

  阅读:25次