The original code looks like this:
for i in top_k:
print(template.format(labels[i], results[i]))
I modified the code to this:
for i in top_k:
outputFile = open('output.txt', 'w')
print(template.format(labels[i], results[i]), file = outputFile)
outputFile.close()
The original code works great since it's printing line by line in the console. But the modified code only prints the last to come from the loop to a .txt file. From what I can tell, it's replacing the text each time the loop runs, so the first text is replaced with the second text, and so forth.