파이썬 - 새로운 데이터를 새로운 csv파일을 추가 생성 후 쓰는 방법?
조회수 3157회
예를들어 특정 아이템에 가격 변동을 시간대별로 프로그램이 실행될때 마다 측정해서 파일로 저장해두고 싶습니다. 아래처럼 할 경우에는 output.csv의 기존 내용이 없어질텐데 어떻게해야 할까요?
import csv
f = open('output.csv', 'w', encoding='utf-8', newline='')
writing = csv.writer(f)
writing .writerow("내용")
f.close()
-
(•́ ✖ •̀)
알 수 없는 사용자 - 〉
1 답변
-
https://docs.python.org/3/library/functions.html#open
위의 문서에서 open 의 옵션을 보세요.
'a' open for writing, appending to the end of the file if it exists
f = open('output.csv', 'a', encoding='utf-8', newline='')
하시면 됩니다.
댓글 입력