[Tutor] How do I fix the following error? Code and error message supplied.

Nathan Pinno falcon3166 at hotmail.com
Thu Aug 4 03:58:38 CEST 2005


Hey all,

How do I fix the following error:
<begin error>
File to load: passcard.txt

Traceback (most recent call last):
  File "D:\Python24\password.py", line 82, in -toplevel-
    load_file(sitelist,filename)
  File "D:\Python24\password.py", line 51, in load_file
    [site,ID,passcard] = string.split(in_line,",")
  File "D:\Python24\lib\string.py", line 292, in split
    return s.split(sep, maxsplit)
AttributeError: 'list' object has no attribute 'split'
<end error>
<begin code>
#This is for a password protected program to store passwords.
import string
password = "hello"
sitelist = {}

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) Load info"
    print "6) Save info"
    print "9) Exit"

def add_site():
    print "Add a login info card"
    site = raw_input("Site: ")
    ID = raw_input("User ID: ")
    passcard = raw_input("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"

def load_file(sitelist,filename):
    in_file = open(filename,"r")
    while 1:
        in_line = in_file.readlines()
        if in_line == "":
            break
        in_line = in_line[:-1]
        [site,ID,passcard] = string.split(in_line,",")
        sitelist[site] = sitelist

def save_file(sitelist,filename):
    out_file = open(filename,"w")
    for site in sitelist.keys():
        out_file.write(site+","+sitelist[site][0]+","+sitelist[site][1]+"\n")
    out_file.close()

print "The Password Program"
print "By 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? ")

print "Welcome to the second half of the program."
while 1:
    main_menu()
    menu_choice = int(raw_input("Choose an option (1-6, 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 == 5:
        filename = raw_input("File to load: ")
        load_file(sitelist,filename)
    elif menu_choice == 6:
        filename = raw_input("Filename to save as: ")
        save_file(sitelist,filename)
    elif menu_choice == 9:
        break
    else:
        print "That's not an option!"
print "Have a nice day!"
<end code>

Thanks in advance,
Nathan Pinno,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050803/7cca3b12/attachment.htm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Pinno, Nathan Paul.vcf
Type: text/x-vcard
Size: 630 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20050803/7cca3b12/PinnoNathanPaul.vcf


More information about the Tutor mailing list