name_list = ['张三', '李四', '王五', '赵六']
age_list = [25, 45, 22, 30]
from csv import *
with open('d:/pythonp/stu.csv', 'w') as wf:
wr = writer(wf) # 声明写对象
wr.writerow(['name', 'age']) # 写入列标题
for i in range(len(name_list)): # 写入行数据
wr.writerow(name_list[i], age_list[i])
with open('d:/pythonp/stu.csv', 'r') as rf:
reader = reader(rf)
for line in reader:
print(line)
通过python对本地文件csv进行读/写操作
最新推荐文章于 2024-05-11 11:32:04 发布