首页 > 代码库 > python 文件操作(pickle)

python 文件操作(pickle)

>>> with open(‘text.txt‘,‘wb‘) as data:
pickle.dump([‘a‘,‘b‘,2],data) 保存到文件


>>> with open (‘text.txt‘,‘rb‘) as rdata:
a_list=pickle.load(rdata)从文件恢复并放到a_list


>>> print(a_list)打印

使用with就不用再写data.close();

python 文件操作(pickle)