I am trying to compare a string with the text from a text file. For some reason though, it's coming back as not the same even though I've literally copied and pasted the text from the text file to my string. I also checkhow to compare a string with a text file to make sure I was doing it right and I am so I am super confused on why this isn't working.
string = "This is working"
x = open('work.txt').read()
print(string)
print(x)
print(x is string)
The content of the text file is This is working and when I run the code I get the output below
This is working
This is working
False
Edit: I also already tried:
if string == open('work.txt').read():
print("Working")
else:
print("Not working")
and that also gives out Not working
isand==are not the same thing. you can read more about the difference in the docs==also fails. Did you perhaps include a line feed in yourread?