Python 读写 CSV 文件
typical usage
注意dictwriter需要提供fieldnames
with open('csvfile', 'wt', newline='') as f:
writer = csv.DictWriter(f, fieldnames=[], extrasaction='ignore')
writer.writeheader()
writer.writerow(d) # list of dict if writerows
with open('csvfile', 'wt', newline='') as f:
writer = csv.writer(f)
writer.writerow(l) # list of list if writerows
with open('csvfile', 'rt') as f:
reader = csv.reader(f)
for row in reader:
print(row)