CSVの書き込み
import csv with open('trial.csv', 'w', newline='') as csv_file: fieldnames = ['Product', 'Price'] writer = csv.DictWriter(csv_file, fieldnames=fieldnames) writer.writeheader() writer.writerow({'Product': 'Raffia', 'Price': 9800}) writer.writerow({'Product': 'Paper', 'Price': 200})
CSVの読み込み
import csv with open('trial.csv', 'r')as csv_file: reader = csv.DictReader(csv_file) for row in reader: print(row['Product'], row['Price'])