Here is the code
f = open("mmk.tsv")
g = f
for a in f:
print("-")
for b in g:
print("+")
The output is only one "-" and several "+"s.
When I remove the inner loop the outer loop works as expected.
Here is the code
f = open("mmk.tsv")
g = f
for a in f:
print("-")
for b in g:
print("+")
The output is only one "-" and several "+"s.
When I remove the inner loop the outer loop works as expected.
You can only iterate over a file once. Doing it through different variables doesn't change that.
Read file file into a list, then you can have multiple iterations.
with open("mmk.tsv") as f:
lines = f.readlines()
for a in lines:
print("-")
for b in lines:
print("+")