import csv
rows = [['1', '2', '3'], ['4', '5', '6']]
with open('my.csv', 'w+', newline='') as csv_file:
writer = csv.writer(csv_file)
for row in rows:
writer.writerow(row)
with open('my.csv', 'r+', newline='') as csv_file:
reader = csv.reader(csv_file)
for row in reader:
print(str(row))
>>> import csv
>>> with open(r'C:\Users\Administrator\Desktop\tongcheng1.csv') as csvfile:
reader=csv.DictReader(csvfile)
for row in reader:
print(row['title'],row['price'],row['date'],row['area'])
>>> datas=[{'title':'我喜欢你','price':'0000','date':'20190-5-04','area':'pudong district'}]
>>> with open(r'C:\Users\Administrator\Desktop\tongcheng1.csv','w') as csvfile:
wr
Python CSV Reader/Writer/DictReader/DictWriter例子
最新推荐文章于 2024-09-28 17:00:00 发布
这篇博客详细介绍了如何使用Python的CSV模块进行数据读写,包括CSV Reader、Writer、DictReader和DictWriter的基本用法,通过实例解析了各个函数的功能和操作步骤。
摘要由CSDN通过智能技术生成