编程语言
首页 > 编程语言> > python 将txt文件转为csv文件

python 将txt文件转为csv文件

作者:互联网

import csv
a = []
f = open('follow_name_1.txt','r',encoding='utf-8')
line = f.readline()
while line:
    a.append(line.split())#保存文件是以空格分离的
    line = f.readline()
f.close()
fp = open('follow_name_1.csv','w',encoding='utf_8_sig',newline="")
csvwriter=csv.writer(fp)
csvwriter.writerows(a)
print("finish")

标签:文件,csv,encoding,python,follow,line,txt,open
来源: https://www.cnblogs.com/FrostyForest/p/16558813.html