从文件中读取一组点并制作.OFF文件

时间:2014-02-15 10:13:18

标签: python shell

我遇到在文件中每行的开头和结尾添加字符并在其间添加“,”的问题。

该文件包含一组点:

657648.688 4772318.920 133.542
657650.269 4772318.841 133.578

因此编辑完文件后,内容应如下所示:

[657648.688, 4772318.920, 133.542]
[657650.269, 4772318.841, 133.578]

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

with open("input.txt") as infile, open("output.txt", "w") as outfile:
    for line in infile:
        outfile.write("[" + ", ".join(line.strip().split()) + "]\n")