Convert a space delimited file to comma separated values file in python

前端 未结 8 985
陌清茗
陌清茗 2021-01-04 06:11

I am very new to Python. I know that this has already been asked, and I apologise, but the difference in this new situation is that spaces between strings are not equal. I

相关标签:
8条回答
  • 2021-01-04 06:58

    Why not to read a file line by line? Split a line into a list then rejoin a list with ','.

    0 讨论(0)
  • 2021-01-04 06:59

    For Merging Multiple text files in one CSV

    import csv
    import os
    for x in range(0,n):            #n = max number of files 
        with open('input{}.txt'.format(x)) as fin, open('output.csv', 'a') as fout:
           csv_output=csv.writer(fout)
           for line in fin:
                csv_output.writerow(line.split())
    
    0 讨论(0)
提交回复
热议问题