CSV関連
csv形式でのファイルの読み込み&書き込み
# -*- coding: utf-8 -*-import csv#csvファイルの書き込みwith open("sample.csv","w") as w: cw = csv.writer(w,lineterminator='\n') cw.writerow(["県名","県庁所在地","面積[m^2]"]) cw.writerow(["愛知","名古屋","5172.92"]) cw.writerow(["青森","青森","9645.64"]) cw.writerow(["秋田","秋田","11637.52"])#csvファイルの読み込みwith open("sample.csv","r") as r: cr = csv.reader(r) for row in cr: print(row)
出力結果(print(row))
['県名', '県庁所在地', '面積[m^2]']['愛知', '名古屋', '5172.92']['青森', '青森', '9645.64']['秋田', '秋田', '11637.52']
参考文献