python raise EOFError 错误 10

#!/Users/yicheung/Documents/#Filename:Untitled.pyimportpickleimportosifos.path.exists... #!/Users/yicheung/Documents/
# Filename: Untitled.py
import pickle
import os
if os.path.exists(r'/Users/yicheung/Documents/address.data') == False:
#if exists return True, elseif False
f = open('/Users/yicheung/Documents/address.data','wb')
temp = {'total' : 0}
#creat a dictionary
pickle.dump(temp, f)
#insert temp into f
else:
pass
def add():
f = open('/Users/yicheung/Documents/address.data','rb')
a = pickle.load(f)
f.close()
b = 0
name = input('Please enter the name of the contact to add:')
for key in a.keys():
if key == name:
print 'Contact already exists, add failed'
else:
number = input('Please enter the number:')
information = {name : number}
f.open('/Users/yicheung/Documents/address.data', 'wb')
f.close()
print ('add success')

add()

报错
Traceback (most recent call last):
File "/Users/yicheung/Documents/Untitled.py", line 30, in <module>
add()
File "/Users/yicheung/Documents/Untitled.py", line 16, in add
a = pickle.load(f)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 1384, in load
return Unpickler(file).load()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 864, in load
dispatch[key](self)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 886, in load_eof
raise EOFError
EOFError
展开
 我来答
见贤思齐2016
2020-06-27
知道答主
回答量:4
采纳率:0%
帮助的人:3407
展开全部
应该是对同一个文件,同时执行了多次打开操作造成的!
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式