I am writing an address book on the book Byte of Pyton (task). When adding a new contact, it gives an error. Already tried different options, I can not understand what's the matter.
import shelve class PhoneBook(): mybook = {} f = shelve.open('mybook', flag='n') newbook = {} def add_person(self, newcont, new_phone): self.newcont = newcont self.new_phone = new_phone self.newbook = {self.newcont: self.new_phone} self.mybook.update([self.newbook]) f = self.mybook
The following error: Before that there was no this error, but simply did not add it to the file.
Traceback (most recent call last): File "C:/PythonWork/Kate/phonebookclassi.py", line 76, in <module> phonebook.add_person(newcont, new_phone) File "C:/PythonWork/Kate/phonebookclassi.py", line 12, in add_person self.mybook.update([self.newbook]) ValueError: dictionary update sequence element #0 has length 1; 2 is required