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'
>>>
>>> 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'
>>>
相关文章推荐
- Python 字符串 String 内建函数大全(1)
- 设计模式中的原型模式在Python程序中的应用示例
- Scrapy学习-1
- 深入解析Python设计模式编程中建造者模式的使用
- Python学习十四:filter()
- python版线段树
- Python入门教程 超详细1小时学会Python
- Python爬虫入门七之正则表达式
- Python爬虫入门六之Cookie的使用
- 实验室吃饭记账系统web
- 举例讲解Python设计模式编程中对抽象工厂模式的运用
- Python爬虫入门五之URLError异常处理
- Python内置数据类型之Tuple
- Python爬虫入门四之Urllib库的高级用法
- Python爬虫入门三之Urllib库的基本使用
- Python爬虫入门二之爬虫基础了解
- Python爬虫入门一之综述
- RNN 入门教程 Part 2 – 使用 numpy 和 theano 分别实现RNN模型
- python操作字符串类型json的注意点
- 实例讲解Python设计模式编程之工厂方法模式的使用