自由式学习
992人加入学习
(0人评价)
Python基础知识-pycharm版
价格 免费
承诺服务
该课程属于 1443-李同学-算法方向-计算机视觉-就业:是 请加入后再学习
#读取和写入CSV文件
#引入CSV模块
import csv
#打开文件,注意:如果乱码,请在最后标明encoding的类型
with open("efg.csv","r",encoding='utf-8') as f:
    a_csv=csv.reader(f)#读出文件内容
#    print(list(a_csv))
    for row in a_csv:#用循环读出文件内容
        print(row)
#打开一个新的文件
with open("ee.csv","w") as f:
    #获得一个写入器
    b_csv=csv.writer(f)
    #一行一行的写
    b_csv.writerow(["ID","姓名","年龄"])
    b_csv.writerow(["1001","工藤新一","17"])
    c=[["1002","希希","18"],["1003","黑羽快斗","16"]]
    b_csv.writerow(c)

['\ufeffID', '姓名', '年龄', '破案量']
['1001', '工藤新一', '17', '1000']
['1002', '服部平次', '18', '200']
['1003', '黑羽快斗', '16', '100']

ID,姓名,年龄

1001,工藤新一,17

"['1002', '希希', '18']","['1003', '黑羽快斗', '16']"

 

[展开全文]

import csv

with open('dd.csv','r') as f:

    a_csv=csv.reader(f)

    print(list(a_csv))

 

with open('ee.csv','w')as f:

    b_csv=csv.writer(f)

    b_csv.writerow(['ID','name','age'])

[展开全文]