Python中可以使用Pickle进行数据的二进制保存。
import pickle
# 使用pickle保存为二进制文件
students = {'12345':'小红', '12346': '小白', '12347': '小蓝'}
filename = open('students.pkl', 'wb')
pickle.dump(students, filename)
filename.close()
# 读取二进制文件
readfile = open('students.pkl', 'rb')
stu = pickle.load(readfile)
print(stu)