将txt格式文件转换为csv格式文件

#-*-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)

 

你可能感兴趣的:(数据处理)