CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
jackfrued

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: jackfrued/Python-100-Days
Path: blob/master/Day01-15/code/Day11/file4.py
Views: 729
1
"""
2
读写二进制文件
3
4
Version: 0.1
5
Author: 骆昊
6
Date: 2018-03-13
7
"""
8
import base64
9
10
with open('mm.jpg', 'rb') as f:
11
data = f.read()
12
# print(type(data))
13
# print(data)
14
print('字节数:', len(data))
15
# 将图片处理成BASE-64编码
16
print(base64.b64encode(data))
17
18
with open('girl.jpg', 'wb') as f:
19
f.write(data)
20
print('写入完成!')
21
22