我正在创建一个 dict 来保存姓名和电话号码,通过 pickle 存储到本地。我现在面临的问题是:合并似乎无法正常工作。, 任何想法?谢谢。
import pickle
def add(name,contact):
person= {};
person[name] = contact;
print('new added: ',person);
mycontactfile = 'contactlist.txt';
f = open(mycontactfile,'rb');
storedcontact = pickle.load(f);
f.close();
print('saved list:',storedcontact);
storedcontact.update(person); # add a new contact to the list
f = open(mycontactfile,'wb');
pickle.dump(storedcontact,f);
print('now full list is:' ,storedcontact);