I have a file \"test.txt\":
this is 1st line this is 2nd line this is 3rd line
the following code
lines = open(\"test.txt\"
Yes, file objects are iterables but to go back to the beginning of the file you need to use lines.seek(0), since after the first loop you are at the end of the file.
lines.seek(0)