Here is the error:
Traceback (most recent call last):
File "D:\Python24\password.py", line 91, in -toplevel- save_file(sitelist) File "D:\Python24\password.py", line 22, in save_file for site,ID,passcard in sitelist.items(): ValueError: need more than 2 values to unpack Here is the code:
#This is for a password protected program to store passwords.
import getpass password = "hello" sitelist = {} def load_file(pw):
import os filename = 'passcard.txt' if os.path.exists(filename): store = open(filename,'r') for line in store: site = line.strip() ID = line.strip() passcard = store.next().strip() pw[site] = ID and passcard else: store = open(filename,'w') # create new empty file store.close() def save_file(pw):
store = open('passcard.txt',"w") for site,ID,passcard in sitelist.items(): store.write(site + '\n') store.write(ID + '\n') store.write(passcard + '\n') store.close() def main_menu(): print "1) Add a login info card" print "2) Lookup a login info card" print "3) Remove a login info card" print "4) Print Login info list" print "9) Save and Exit" def add_site():
print "Add a login info card" site = raw_input("Site: ") ID = raw_input("User ID: ") passcard = getpass.getpass("Password: ") sitelist[site] = [ID,passcard] def lookup_site():
print "Lookup a login info card" site = raw_input("Site: ") if sitelist.has_key(site): print "The ID is: ",sitlist[site][0] print "The password is: ",sitelist[site][1] else: print site," was not found." def remove_site():
print "Remove a login info card" site = raw_input("Site: ") if sitelist.has_key(site): del sitelist[site] else: print site," was not found." def print_login_info():
print "Login Info" for site in sitelist.keys(): print "Site: ",site," \tID: ",sitelist[site][0]," \tPassword: ",sitelist[site][1],"\n" print "The Password Program" print "By Nathan Pinno" load_file(sitelist) answer = getpass.getpass("What is the password? ") while password != answer: print "The password is incorrect." answer = getpass.getpass("What is the password? ") print "Welcome to the second half of the program."
while 1: main_menu() menu_choice = int(raw_input("Choose an option (1-4, or 9: ")) if menu_choice == 1: add_site() elif menu_choice == 2: lookup_site() elif menu_choice == 3: remove_site() elif menu_choice == 4: print_login_info() elif menu_choice == 9: break else: print "That's not an option!" save_file(sitelist) print "Have a nice day!" How do I fix the program, so that it will save the info without raising any
errors?
|
BEGIN:VCARD VERSION:2.1 N:Pinno;Nathan;Paul;Mr. FN:Pinno, Nathan Paul NICKNAME:Spam_swatter ORG:Woffee;Executive TITLE:Owner/operator TEL;WORK;VOICE:7806085529 TEL;CELL;VOICE:7806085529 ADR;WORK:;President/CEO;Box 1783;Camrose;Alberta;T4V1X7;Canada LABEL;WORK;ENCODING=QUOTED-PRINTABLE:President/CEO=0D=0ABox 1783=0D=0ACamrose, Alberta T4V1X7=0D=0ACanada ADR;HOME:;;Box 1783;Camrose;Alberta;T4V1X7;Canada LABEL;HOME;ENCODING=QUOTED-PRINTABLE:Box 1783=0D=0ACamrose, Alberta T4V1X7=0D=0ACanada X-WAB-GENDER:2 URL;HOME:http://falcon3166.tripod.com URL;WORK:http://zoffee.tripod.com BDAY:19850221 EMAIL;PREF;INTERNET:[EMAIL PROTECTED] EMAIL;INTERNET:[EMAIL PROTECTED] EMAIL;INTERNET:[EMAIL PROTECTED] EMAIL;INTERNET:[EMAIL PROTECTED] REV:20050810T003852Z END:VCARD
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor