I have the following situation: I'm writing a csv text file and I can not lose the data written on it.
However, in situations like the following, I lose everything I wrote to the fourth iteration.
import csv
import time
file_reference = open('result.csv', 'w', newline='')
file_csv = csv.writer(file_reference, delimiter=';', quoting=csv.QUOTE_MINIMAL)
for i in range(50):
file_csv.writerow([i])
time.sleep(1)
print('...')
if i == 4:
raise ValueError('foo')
file_reference.close()
How could I write to disk the data written in the text file for each execution writerow?