csv:(comma separated values)文件(逗号分隔符文本格式)
用途:用于数据交换、Excel文件和数据库数据的导入和导出
import csv
with open('dd.csv','r',encoding='utf-8') as f:
a_csv=csv.reader(f) #获得csv文件的内容
print(a_csv)
#print(list(a_csv))
for row in a_csv:
print(row)
with open('ee.csv','w',encoding='utf-8') as f:
b_csv=csv.writer(f)
b_csv.writerow(['ID','姓名','年龄']) #向scv每行写入内容
b_csv.writerow(['1001','单单','18'])
b_csv.writerow(['1002','旦旦','18'])
c=[['1003','喜喜','3'],['1004','嘻嘻','4']]
b_csv.writerows(c) #向scv写入所有内容