I am a Python beginner and was troubleshooting a bigger project of mine in a smaller, separate file. The problem with my bigger project was that I could not get two for loops to work consecutively.
I have a txt file containing two lines
The code is simple:
file=open("test.txt","r")
for line in file:
print("x")
pass
print("hi")
for line in file:
print("x")
The two for loops are identical bar pass
.
print("hi")
exists as a means of checking if the first for loop is broken out of (which it is)
This code outputs:
x
x
x
hi
The first for loop is broken out of and the print statement works after it, but the for loop after that doesn't? I would have expected it to output:
x
x
x
hi
x
x
x
How can I fix this?
Thanks