+1 vote
ago in Programming Languages by (17.2k points)
I am writing a large amount of data to an output file. When I check the output file while writing is still in progress, I do not see all written data in the file. Is there any way to fix it so that I can see all the written data?

1 Answer

0 votes
ago by (30.2k points)

The write() function is not flushing the output buffer to the disk and hence you do not see all the written data in the output file.

There flush() function can solve your issue. After the write() function, add the flush() function and you will see the content in the file.


fo = open('opfile.txt', 'w')
for rec in recs: