0

I am trying to write the output to my python program onto a csv file. I print these outputs on the terminal as well for me to see, however the csv file only saves the most recent output. Here is my code snippet for writing to csv, please advice on how I can modify the code so that the csv does not keep getting overwritten with every output instance:

.
.
.
      print (detection_result)
      print (" ")

      outputCSV = open('outputCSV.csv', 'w')
      with outputCSV:
        writer = csv.writer(outputCSV)
        writer.writerow(detection_result)

      print("csv written")
.
.

To which the terminal output looks like so :

csv written
([], 7.267522811889648)

csv written
([], 6.453444063663483)

csv written
([], 6.2553465366363525)

csv written
([], 7.510797679424286)

csv written
([], 6.006504222750664)

But the CSV file has only the following line saved:

[], 6.006504222750664

Please advice on how to rectify this

Veejay
  • 515
  • 3
  • 7
  • 20

0 Answers0