将txt格式文件转换为csv格式文件
程序员文章站
2022-05-28 15:18:04
...
#-*-coding:utf-8 -*-
import csv
with open('file.csv', 'w+',newline='') as csvfile:
spamwriter = csv.writer(csvfile, dialect='excel')
# 读要转换的txt文件,文件每行各词间以@@@字符分隔
with open('1.txt', 'r',encoding='utf-8') as filein:
for line in filein:
line_list = line.strip('\n').split('\t')
spamwriter.writerow(line_list)
上一篇: wav音频转pcm
下一篇: 推荐:为什么要使用OSGi?
推荐阅读