文件名:aa.scv
编号,姓名,年龄,性别
1,账单,16,男
2,里斯,17,女
3,王五,18,男
4,赵六,19,男
# 读取csv import csv # 打开文件 with open('./data/aa.csv','r') as f: csv.reader(f) print(f) for i in f: print(i) # 只读取某一行 with open('./data/aa.csv','r') as f: f1=csv.reader(f) result = list(f1) print(result,result[0]) # 只读取某一列 with open('./data/aa.csv','r')as f: f2 = csv.reader(f) print(f2) for i in f2: print(i[0]) # 往csv 文件写数据 stu1=[6,'续租',18,'男'] stu2=[7,'张思思',88,'男'] with open('./data/aa.csv','a',newline='')as f: # 把数据写到哪 witers1 = csv.writer(f) witers1.writerow(stu1) witers1.writerow(stu2) stus=[ ('小米','qq'), ('小米2','q2q'), ('小米22','q22q'), ] with open('./data/aa.csv','a',newline='')as f: writes=csv.writer(f) for i in stus: writes.writerow(i)