Hello guest, if you read this it means you are not registered. Click here to register in a few simple steps, you will enjoy all features of our Forum.
Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why doesn't this work?
import time
file = open("login.txt","r")
TrueUsername = file.readline(1)
TruePassword = file.readline(2)
print("Log in")
Username1 = input("Username:")
Password1 = input("Password:")

if Username1 == TrueUsername and Password1 == TruePassword:
    print("Try again.")
---Whenever I write the correct password and username on the .txt file it prints "Try again."
Please put your code in Python code tags, you can find help here.
There you go.
you should use configparser.

WAY easier :)
If you print your variables, you will find that the variables created by readline() contain a newline at the end, and the variables created by input do not, so they will never be equal. https://www.tutorialspoint.com/python/file_readline.htm
nilamo likes this post
Hence, going off woooee's comment, you need to split the readline to remove the newline.
Try something like: TrueUsername = file.readline(1).split('\n')[0]
If ^ doesn't work, then do:
TrueUsername = file.readline(1).split('\n')
if Username1 == TrueUsername[0]

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Super simple import doesn't work. Please help! Mustey 9 324 Jul-27-2018, 09:52 AM
Last Post: Mustey
  os.system doesn't generate same result as shell? abc12346 1 113 Jul-24-2018, 11:41 PM
Last Post: micseydel
  len() function doesn't work with Geany Editor hudabaig 2 172 Jun-01-2018, 11:20 PM
Last Post: wavic
  Example of list comprehensions doesn't work Truman 17 737 May-20-2018, 05:54 AM
Last Post: buran
  Simple If Statement doesn't work Jack_Sparrow 3 193 May-14-2018, 09:37 AM
Last Post: ThiefOfTime
  Code doesn't loop after first RFID scan BadgerHack 5 229 May-01-2018, 11:07 AM
Last Post: BadgerHack
  1st Script written doesn't output anything. Need some else's eyes Kym 3 390 Mar-21-2018, 04:19 PM
Last Post: nilamo
  cx-Freeze exe doesn't work ammann 1 311 Mar-19-2018, 10:58 AM
Last Post: buran
  curses.initscr doesn't work zaphod424 3 396 Feb-28-2018, 12:36 PM
Last Post: Gribouillis
  Why doesn't this code work? hsezgin 4 324 Jan-12-2018, 01:44 PM
Last Post: hsezgin

Forum Jump:

Users browsing this thread: 1 Guest(s)