Compare raw_input with text in file
I am learning python and just trying to play with some different functionality. I created this script to map raw_input to a file, but it always returns as not matching. Here is the script. Can you tell me what I am doing wrong?
#This is a test script to check a password
word = raw_input("what is the password ") #input data
f = open("test.txt").read()
if word == f:
print "Match"
else:
print "No Match"
+3
Jarrid
source
to share
1 answer
Just remember to remove the newline or space at the end of the file. Otherwise use:
if word == f.rstrip():
...
+1
JuniorCompressor
source
to share