fork download
  1. import pickle
  2.  
  3. class AddressBook:
  4.  
  5. dict = {}
  6.  
  7. def addphone(self, name, phone):
  8. if name not in AddressBook.dict.keys():
  9. AddressBook.dict[name] = phone
  10. else:
  11. print('{0} at that moment in dictionary'.format(name))
  12.  
  13. def printbook(self):
  14. if not all(keys == 0 for keys in AddressBook.dict.keys()):
  15. for name, phone in AddressBook.dict.items():
  16. print('name: {0}\tphone: {1}'.format(name, phone))
  17. else:
  18. print('Dictionary is empty.')
  19.  
  20. def deletePhone(self, name):
  21. if name in AddressBook.dict.keys():
  22. del AddressBook.dict[name]
  23. else:
  24. print('No {0} in dictionary'.format(name))
  25.  
  26. def changephone(self, name, newphone):
  27. if name in AddressBook.dict.keys():
  28. AddressBook.dict[name] = newphone
  29. else:
  30. print('No {0} in dictionary'.format(name))
  31.  
  32. def searchphone(self, name):
  33. if name in AddressBook.dict:
  34. print(AddressBook.dict[name])
  35. else:
  36. print('No {0} in dictionary'.format(name))
  37.  
  38. def savebook(self):
  39. pickle.dump(AddressBook.dict, open('dict.p', 'wb'))
  40.  
  41. def loadbook(self):
  42. dict2 = pickle.load( open('dict.p', 'rb'))
  43. print(dict2)
  44.  
Success #stdin #stdout 0.04s 10352KB
stdin
Standard input is empty
stdout
Standard output is empty