I\'m trying to output the result of my script into a text file. The script is working fine, the only problem is when results are saved into the text file (output.txt), only
I'm going to take a wild guess and assume that all of this code happens inside a loop. Each time through the loop, you write one more line, but at the end, you only have the last line.
If that's the problem, here's the issue:
f = open("output.txt", "w")
When you open a file in 'w' mode, that truncates any existing file.
To fix this, either open the file once, outside the loop, instead of over and over again, or open it in 'a' mode or 'r+' mode or some other mode that doesn't truncate the file.
The documentation for the open function, or the inline help in the interactive interpreter, explains what all the different modes mean.