I am working on writing result on a file repeatedly. There are N steps, so I need to write the result for each step on the same file. Then, another module uses the file for the step.
Here is the issue. The file size is 0, so I cannot do the next step.
while 1:
file = open('a.txt','w+')
run()
file.write(result)
file.close()
This simple code is the summary of my code.
Please help me out.
Thanks in advance.
Did you forget to assign to
result?Also,
w+truncates the file. Did you mean to saya+? With your current code, if you kill the infinite loop at any point other than right after theclose()(and before the next iteration’sopen()), the output file will likely be empty.