#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

    TXT File reading


    Hi, i'm relatively new to python programming and have been asked to do a project for university. I'm attempting to make a user account program with a register, login and lost password function.

    I've decided to go down the route of when a user register their account, the vars to temporarily store the username, email & pw are then added to a dictionary. The dictionaries at the end of the registration then are saved to a external txt file.

    I have reached my first problem in that I don't know how to read from the text files and create an if statement to check whether an email exists for example.

    The code so far:

    option = True
    register = True

    userdict = {}
    pwddict = {}
    emaildict = {}

    f = open('db.txt', 'a')

    while (option):
    print("""Choose from one of the following options...
    1) Register
    2) Login
    3) Lost Password""")
    option = input("")
    if option == '1' or option == 'register':
    print("You have chosen to register")
    option = False
    elif option == '2' or option == 'login':
    print("You have chosen to login")
    option = False
    elif option == '3' or option == 'lost password':
    print("You have chosen the lost password function")
    option = False
    else:
    pass

    print("We will need a username, your email and a password.")
    username = input(str("Type your desired username: "))
    email = input(str("Type your email address: "))
    password = input(str("Type your password: "))

    emaildict [username] = email
    pwddict [username] = password
    print("Your details have been saved, you will receive email confirming containing your details shortly.")
    f.write(str(userdict))
    f.write(str(emaildict))
    f.write(str(pwddict))
    Any help is appreciated!
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,854
    Rep Power
    481
    I'm sure your question is interesting and important.

    You should use the pickle or shelve module. These are documented here. python 2

    or python3 here
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo