Also -

menu_choice = input("Choose an option: ")

input() is always bad. Use int(raw_input(""Choose an option: ")) instead. input() evaluates your input as a Python _expression_ - I could select 9 by entering 5+4

or, I could enter sys.exit() and drop to DOS (or whatever it's running on.) or far more malicious code, like deleting everything on C: drive

list[site] = id and passcard
I'm not sure if that's real or a comment. Possibly you meant list[site] = id + passcard ?


...Or, it could be this -

if site.has_key(site):
            print "The ID is: ",id(site)
            print "The password is: ",passcard(site)

id(site) - if you have functions called id and passcard, I can't see them, if id and passcard are collections (list/dictionary) I can't see them.

If they are functions, id() is a builtin Python function.

If they are collections, then the correct way to access member items is to use id[site] or
passcard[site].

But, now I'm guessing. Please post error message. And, if you need to post code, please post all relevant code, I recommend http://www.rafb.net/paste/ to have it formatted nicely and even colour coded.

Regards,

Liam Clarke


On 7/5/05, Liam Clarke <[EMAIL PROTECTED]> wrote:
What error messages are you getting? Please post the full message.

On 7/5/05, Nathan Pinno < [EMAIL PROTECTED] > wrote:
What's wrong with this code? I'm using 2.2.3 if this helps.
 
#This is for a password protected program to store passwords.
password = "hello"
print "The Password Program"
print "Copywrite 2005. All Rights Reserved."
print
answer = raw_input("What is the password? ")
while password != answer:
    print "The password is incorrect."
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 = 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
    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."
    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."
    elif menu_choice == 4:
        print "Login Info"
        for x in site.keys():
            print "Site: ",x," \tID: ",numbers[x]," \tPassword: ",numbers[x]
        print
    elif menu_choice == 5:
        filename = raw_input("Filename to save: ")
        save_login(list,filename)
    elif menu_choice == 6:
        filename == raw_input("Filename to load: ")
        load_login(list,filename)
print "Have a nice day!"
Thanks,
Nathan Pinno
Crew, McDonalds Restaurant, Camrose, AB Canada
http://www.npinnowebsite.ca/


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor





--
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.'



--
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.'
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to