Thanks Wolfram for help with that error.

  Here's another that popped up:

  Traceback (most recent call last):
    File "D:\password.py", line 68, in ?
      for x in site.keys():
  AttributeError: 'str' object has no attribute 'keys'

  How to fix it?

  Thanks,
  Nathan Pinno
  ----- Original Message ----- 
  From: "Wolfram Kraus" <[EMAIL PROTECTED]>
  To: <tutor@python.org>
  Sent: Thursday, July 07, 2005 1:02 AM
  Subject: Re: [Tutor] Why is this error showing up? (Original Message: 
(Tutor) What's wrong with this code?) Ignore previous post.


  > You wrote filename == raw_input("Filename to load: ") instead of
  > filename = raw_input("Filename to load: ")
  >
  > HTH,
  > Wolfram
  >
  > Nathan Pinno wrote:
  >> Hi all,
  >>
  >> Here's one of the messages that pops up:
  >>
  >> Traceback (most recent call last):
  >>   File "D:\password.py", line 77, in ?
  >>     filename == raw_input("Filename to load: ")
  >> NameError: name 'filename' is not defined
  >>
  >> Why is it popping up whenever I try to load a file?
  >>
  >> Here's the latest code:
  >>
  >> # This is the code for a password protected program to store passwords.
  >> password = "hello"
  >> print "The Password Program"
  >> print "Copyright 2005 Nathan Pinno."
  >> print
  >> answer = raw_input("What is the password? ")
  >> while password != answer:
  >>     print "The password is incorrect."
  >>     answer = raw_input("What is the password? ")
  >> 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 "5) Save login list"
  >>     print "6) Open Login list"
  >>     print "9) Exit"
  >>
  >> def load_login(site,filename):
  >>     in_file = open(filename,"r")
  >>     while 1:
  >>         in_line = in_file.readline()
  >>         if len(in_file) == 0:
  >>             break
  >>         in_line = in_line[:-1]
  >>         [site,id,passcard] = string.split(in_line,",")
  >>         list[site] = id and passcard
  >>     in_file.close()
  >>
  >> def save_login(site,filename):
  >>     out_file = open(filename,"w")
  >>     for x in site.keys():
  >>         out_file.write(x+","+sites[x]+"\n")
  >>     out_file.close()
  >>
  >> menu_choice = "0"
  >> list = {}
  >> print "Welcome to the second half of the program."
  >> print main_menu()
  >> while menu_choice != "9":
  >>     menu_choice = raw_input("Choose an option: ")
  >>     if menu_choice == "1":
  >>         print "Add a login info card"
  >>         site = raw_input("Site: ")
  >>         id = raw_input("User ID: ")
  >>         passcard = raw_input("Password: ")
  >>         list[site] = id and passcard
  >>         menu_choice = raw_input("Choose an option: ")
  >>     elif menu_choice == "2":
  >>         print "Lookup a login info card"
  >>         site = raw_input("Site: ")
  >>         if site.has_key(site):
  >>             print "The ID is: ",id(site)
  >>             print "The password is: ",passcard(site)
  >>         else:
  >>             print site," was not found."
  >>         menu_choice = raw_input("Choose an option: ")
  >>     elif menu_choice == "3":
  >>         print "Remove a login info card"
  >>         site = raw_input("Site: ")
  >>         if sites.has_key(site):
  >>             del numbers[site]
  >>         else:
  >>             print site," was not found."
  >>         menu_choice = raw_input("Choose an option: ")
  >>     elif menu_choice == "4":
  >>         print "Login Info"
  >>         for x in site.keys():
  >>             print "Site: ",x," \tID: ",numbers[x]," \tPassword: 
",numbers[x]
  >>         print
  >>         menu_choice = raw_input("Choose an option: ")
  >>     elif menu_choice == "5":
  >>         filename = raw_input("Filename to save: ")
  >>         save_login(list,filename)
  >>         menu_choice = raw_input("Choose an option: ")
  >>     elif menu_choice == "6":
  >>         filename == raw_input("Filename to load: ")
  >>         load_login(list,filename)
  >>         menu_choice = raw_input("Choose an option: ")
  >> print "Have a nice day!"
  >>
  >> Anything else that needs addressing?
  >>
  >> Thanks,
  >> Nathan Pinno
  >> http://www.npinnowebsite.ca/
  >>
  >
  > _______________________________________________
  > Tutor maillist  -  Tutor@python.org
  > http://mail.python.org/mailman/listinfo/tutor
  >
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to