[Python] Read, append on csv

jasonlee1995·2022년 5월 26일
0

Use python library csv to read and append new contents on csv file

1. Read csv file

import csv

csv_dir = './csv_to_read.csv'

with open(csv_dir, 'r') as csvfile:
    csvreader = csv.reader(csvfile)
    for line in csvreader:
        print(line)

2. Append contents on csv file

import csv

csv_dir = './csv_to_append.csv'

with open(csv_dir, 'a') as csvfile:
    csvwriter = csv.writer(csvfile)
    csvwriter.writerow(['Test'])
    csvwriter.writerow([1, 2, 3, 4])
    csvwriter.writerow([])
    
profile
Computer Vision Researcher

0개의 댓글