import csv
with open('test.csv', 'w+', newline='') as csv_file:
fieldnames = ['Name', 'Count']
writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
writer.writeheader()
writer.writerow({'Name':'A', 'Count':1})
writer.writerow({'Name':'B', 'Count':2})
csv_file.seek(0)
reader = csv.DictReader(csv_file)
for row in reader:
print(row['Name'], row['Count'])
実行結果
A 1
B 2