python txt文件转为csv文件

import csv
 
out = open('20190905.csv','w',newline='')
csv_writer = csv.writer(out,dialect='excel')  
 
f = open("20190901.txt","r")
for line in f.readlines():
     line=line.replace(',','\t')   #将每行的逗号替换成空格
     list = line.split()          #将字符串转为列表,从而可以按单元格写入csv
     csv_writer.writerow(list)
View Code

(6条消息) python将txt文件转为csv文件_古杜且偲的博客-CSDN博客_txt转csv

posted @ 2023-02-23 16:23  ༺༽秋水.无痕༼༻  阅读(279)  评论(0编辑  收藏  举报
……