python操作csv

按行读取

import csv

with open(filename, 'r', encoding="utf-8") as f:
    reader = csv.reader(f)
    print(type(reader))
    for row in reader:
        print(row)

写csv

import csv


with open('res.csv', 'w', newline='', encoding="utf-8") as fp:
    writer = csv.writer(fp)
    headers = ["序号",]
    writer.writerow(headers)
    writer.writerow(列表)

你可能感兴趣的:(python,python,开发语言)