有勇气的牛排博客

python操作csv

有勇气的牛排 228 Python 2023-05-18 21:05:09

1 按行读取

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

2 写csv

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

留言

专栏
文章
加入群聊