Python 读写.csv文件

写入:write.py

#!/usr/bin/python
# -*- coding:utf-8 -*-

import csv

print("Test for csv write")

p1 = ['kevin',20]
p2 = ['jason', 16]
p3 = ['frank', 35]

out = open("1.csv",'a',newline='')
csv_write = csv.writer(out ,dialect='excel')
csv_write.writerow(p1)
csv_write.writerow(p2)
csv_write.writerow(p3)
print("write over")
 

读取 read.py

#!/usr/bin/python
# -*- coding:utf-8 -*-

import csv

csvf = csv.reader(open("1.csv",'r'))
for stu in csvf:
    print(stu)

上一篇:CODING —— 云原生时代的研发工具领跑者


下一篇:python有序序列的字典序列推导式运用技巧!