您的位置:首页 > 编程语言 > Python开发

python3 encode decode base64

2016-03-02 11:19 316 查看
python3 base64时需要byte类型,encode默认编码为utf-8,decode默认将utf-8解码成我们能看懂的字符

>>> a = base64.b64encode('中'.encode())
>>> a
b'5Lit'
>>> type(a)
<class 'bytes'>
>>> b = base64.b64encode('中'.encode()).decode()
>>> b
'5Lit'
>>> type(b)
<class 'str'>
>>> type('中')
<class 'str'>
>>> c = base64.b64decode(a)
>>> c
b'\xe4\xb8\xad'
>>> type(c)
<class 'bytes'>
>>> c = base64.b64decode(a).decode()
>>> c
'中'
>>> type(c)
<class 'str'>
>>> '中'.encode()
b'\xe4\xb8\xad'
>>>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: