For example, I want to measure the price change for a specific item every time the program runs by time and save it as a file. If we do it as below, the existing contents of output.csv will disappear, so what should we do?
import csv
f = open('output.csv', 'w', encoding='utf-8', newline='')
writing = csv.writer(f)
writing.writerow ("Content")
f.close()
https://docs.python.org/3/library/functions.html#open
Look at the options of open in the above document.
'a' open for writing, appending to the end of the file if it exists
f = open('output.csv', 'a', encoding='utf-8', newline='')
You can do it.
© 2024 OneMinuteCode. All rights reserved.