【发布时间】:2020-07-14 07:07:41
【问题描述】:
import pickle
#writing into the file
f = open("essay1.txt","ab+")
list1 = ["Aditya","Arvind","Kunal","Naman","Samantha"]
list2 = ["17","23","12","14","34"]
zipfile = zip(list1,list2)
print(zipfile)
pickle.dump(zipfile,f)
f.close()
#opening the file to read it
f = open("essay1","ab")
zipfile = pickle.load(f)
f.close()
输出是:
runfile('E:/Aditya Singh/Aditya Singh/untitled3.py', wdir='E:/Aditya Singh/Aditya Singh')
<zip object at 0x0000000008293BC8>
Traceback (most recent call last):
File "E:\Aditya Singh\Aditya Singh\untitled3.py", line 21, in <module>
zipfile = pickle.load(f)
UnsupportedOperation: read
【问题讨论】:
-
为什么要使用
ab模式打开文件? -
会不会是文件名有误?你写了essay1,但它看起来应该是essay1.txt。
标签: python pickle file-handling