python读取、写入csv文件

import csv,re

#打开wsx.csv文件,为了后面写入做准备
with open("wsx.csv", "w", encoding="utf-8", newline='') as w: #newline='',这个参数的作用是防止生成的csv隔一行空一行,如果没有这个参数,csv文件汇总就会隔一行空一行
writer = csv.writer(w)
  
  #读取出来123.csv文件的内容,并把读取出来的内容写入到wsx.csv文件中
with open("123.csv", "r", encoding="utf-8") as fp:
t = csv.reader(fp)
for i in t:
print(i) #这里读取出来的i是列表格式
writer.writerow(i)

# import csv
# a = "text"
# b = "18"
# with open("456.csv","a",encoding="utf-8") as fp:
# writer = csv.writer(fp)
#
# writer.writerow([a,b])
posted @ 2019-11-28 21:32  乔儿  阅读(447)  评论(0编辑  收藏  举报