请问大神怎样使用Python中的pickle模块把一个文本文件中所有内容改成存储为序列化模式?
发布网友
发布时间:2022-11-27 08:28
我来回答
共1个回答
热心网友
时间:2023-10-15 13:57
import pickle
with open('hello.txt', 'r') as fr:
data = fr.read()
print(data)
with open('data.pickle', 'wb') as fw:
pickle.mp(data, fw, pickle.HIGHEST_PROTOCOL)
with open('data.pickle', 'rb') as fr:
data = pickle.load(fr)
print(data)