I have a program, in which I need to load a string from inside a text file to a variable. It looks something like this (I have code that makes sure the file in the given path exists prior to this):
file = open("path to the file", "r")
if file.read() != "":
msg = file.read()
print("String is not empty, here's what it said: " + file.read() + ", here's what was saved: " + msg)
When I run the code, it returns this:
String is not empty, here's what is said: , here's what was saved:
When I open the text file, I can clearly see its content isn't empty, it's a normal string of text. That means that for some reason, the read() function fails to read the string that is clearly there. I have done all the bug searching I could've with my level of skill, made sure all my paths and stuff are correct and there aren't any typos, and searched through many stack overflow posts, none of which contained a solution to my problem. What could be causing this problem? If I failed to mention an important part of my code, please ask me for it.