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

前端 未结 8 1019
陌清茗
陌清茗 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:54

    for converting "space" to ","

    only fill the filename to what you want

    with open('filename') as infile, open('output', 'w') as outfile:
        outfile.write(infile.read().replace(" ", ","))
    

    for converting "," to "Space"

    with open('filename') as infile, open('output', 'w') as outfile: outfile.write(infile.read().replace(",", " "))

提交回复
热议问题