当前位置:   article > 正文

python读写csv文件,使用csv.reader()方法及csv.writer()方法_简述csv中reader()和writer()的用法

简述csv中reader()和writer()的用法
python读写csv文件,使用csv.reader()方法及csv.writer()方法

import csv

with open(r"C:\郑宏宇\python_learn\c.csv","r") as f:
    a_csv = csv.reader(f)
    for row in a_csv:
        print(row)

with open(r"C:\郑宏宇\python_learn\c.csv","w")as f:
    b_csv = csv.writer(f)
    b_csv.writerow(["id","姓名","年龄"])              #writerow按行写入
    b_csv.writerow(["1001", "郝佳", "18"])

    c = [["1002","明明","5"],["1003","东东","4"]]
    b_csv.writerows(c)

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/212608?site
推荐阅读
相关标签
  

闽ICP备14008679号