I add a new name to this script, but when I want to quit and save
it gives and error
ValueError: need more than 2 values to unpack
I have no idea what it means can someone help me?
If you want to modify the program feel free...
filename = "movielog.dat"
def readBook(book):
import os
if os.path.exists(filename):
store = open(filename, 'r')
for line in store:
name = line.rstrip()
year = store.next().rstrip()
roles = store.next().rstrip()
book[name] = year, roles
store.close()
def saveBook(book):
store = open(filename, 'w')
for name,year,roles in book.items():
store.write(name + '\n')
store.write(year + '\n')
store.write(roles + '\n')
store.close()
def getChoice(menu):
print menu
choice = int(raw_input("Select a choice(1-4): ") )
return choice
def addEntry(book):
name = raw_input("Enter a name: ")
year = raw_input("Enter year and director: ")
roles = raw_input("Enter leading roles (male and female): ")
book[name] = year, roles
def removeEntry(book):
name = raw_input("Enter a name: ")
del(book[name])
def findEntry(book):
name = raw_input("Enter a name: ")
if name in book:
print name, book[name]
else:
print "Sorry, no entry for: ", name
def main():
theMenu = '''
1) Add entry
2) Remove entry
3) Find entry
4) Quit and save
'''
theBook = {}
readBook(theBook)
choice = getChoice(theMenu)
while choice != 4:
if choice == 1:
addEntry(theBook)
elif choice == 2:
removeEntry(theBook)
elif choice == 3:
findEntry(theBook)
else : print "Invalid choice, try again"
choice = getChoice(theMenu)
saveBook(theBook)
if __name__ == "__main__":
main()