更容易在Python中为所有输出行添加"\n"?

Hou*_*man 0 python

以下脚本适用于我,但我想知道是否可以更简单的方式完成.我使用的是Python 2.7.3.

f = open('file.txt')
out = open('script.sql', "w")
for line in f:
        out.write('%s%s' % (line[:-1], '\n'))
f.close()
out.close()
Run Code Online (Sandbox Code Playgroud)

谢谢,

Cat*_*lus 6

嗯,有line[:-1] + '\n'.