I have a file named text.txt which contains the following data:
with open("text.txt") as f:
for i in xrange(5):
print "Is\n" in f
You're consuming your file at the first test, so you're at the end of the file for the other iterations.
You could read the contents to a string, but since you don't want to store the file, I propose to
seek to beginning of the file instead:
with open("test.txt") as f: for i in range(5): f.seek(0) print ("Is\n" in f)