import csv
headers = ['class','name','sex','height','year']
rows = [
[1,'xiaoming','male',168,23],...,'female',162,22],
[2,'xiaozhang','female',163,21],
[2,'xiaoli','male',158,21]
]
with open('test.csv...','w')as f:
f_csv = csv.writer(f)
f_csv.writerow(headers)
f_csv.writerows(rows)
import csv
headers...','w',newline='')as f:
f_csv = csv.DictWriter(f,headers)
f_csv.writeheader()
f_csv.writerows(rows)...读
import csv
with open('test.csv')as f:
f_csv = csv.reader(f)
for row in f_csv:
print(row)