txt转化为csv

代码示例:

import csv

with open('F:\\test.csv','w') as f:
    f_csv=csv.writer(f)
    for line in open('F:\\trainlist01.txt', 'r'):
        new_line = line.strip().split()
        f_csv.writerow(new_line)

txt文件:
txt转化为csv_第1张图片
csv文件:
txt转化为csv_第2张图片

参考:
https://blog.csdn.net/katyusha1/article/details/81606175
https://www.cnblogs.com/youyou0/p/8921719.html

你可能感兴趣的:(python)