python raise EOFError 错误

#!/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

应该是对同一个文件,同时执行了多次打开操作造成的!
温馨提示:答案为网友推荐,仅供参考