CSV写入与读取-Python
1 #写入CSV 2 import csv 3 csvfile=open("d://text1.csv","w",newline="") #newline为空可以防止写入时空开一行空白行 4 writer=csv.writer(csvfile) 5 writer.writerow(["姓名","年龄","编号"]) #writerow写入一行数据 6 data=[("夏明","18","125846"),("小新","22","159345")] #写入元组与列表一样 7 writer.writerows(data) #writerows写入多行数据 8 csvfile.close()