Dear community I have a problem that although it's seems to be not a big deal, it took away sleep from me. and I don't need sleep, I NEED answer!
I want to open a file, and if the string "MODIFIED" was in the file's content, I want to print('already modified'), then printing the content of the file here is my code:
with open(f"contents\\docs.txt", "r") as f:
if "MODIFIED" in f.readlines():
print("already modified")
print(f.readlines())
print()
it's seems to be ok, but the weird part is, the file does not contain the string "MODIFIED", so it's just have to normally print the content of the file, but is only return a empty list [] ! (The file is not empty!) and if I run it without the if statement, it will normally return the content as it should.
with open(f"contents\\docs.txt", "r") as f:
#if "MODIFIED" in f.readlines():
#print("already modified")
print(f.readlines())
print()
I just don't get it, what does a if statement do to the code that the code return empty list.
- the doc.txt file that I want to return it's content
before the flood
david attenborough: a life on our planet
an inconvenient truth
home 2009
kiss the ground 2020
seaspiracy 2020
cosmos
it's the first time I'm encountering this, idk what to call it, bug?
I would appreciate if you guys help me find out what's going wrong