python 脚本处理文件在文件中的每一行末尾添加逗号

来源:互联网 发布:手机淘宝怎么上门取件 编辑:程序博客网 时间:2024/04/29 21:44

现有文件内容如下:

这里写图片描述

现在需要把文件中的每一行上加上引号,并在行尾添加逗号, 即如下效果:

这里写图片描述

”瑞士军刀“ python 脚本上场。

import oswith open('input.txt', 'rb') as lines:     with open('output.txt', 'wb') as outfile:        for line in lines:            line = '"' + line.replace(os.linesep, "") + '",' + os.linesep            outfile.write(line)

不算空行,6行代码。

0 0