通过python对本地文件csv进行读/写操作

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)