1

I have made a password prog to input the first line of the file as the password and then upon accessing the file the prog should ask the password and only if the password is right should the contents of the file be printed. But I just can’t get it to work. Pls help.

p=open("abc.txt", 'w+')
p.write("T") #< password
p.write("\n")
p.write("work pls")
p.close()
p=open("abc.txt", 'r+')
y=raw_input('pass')
if str(p.readline())==str(y):
    print p.read()
else:
    print "Password incorrect"
p.close()

1 Answer 1

2

readline() returns the line, including the trailing new line. You have to strip it off:

if p.readline().rstrip() == y:
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.