#读取和写入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']"