CSV写入与读取-Python[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()
hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 » CSV写入与读取-Python