欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

将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)

 

相关标签: Dataprocess