到目前为止,我有这个代码:
f = open("text.txt", "rb")
s = f.read()
f.close()
f = open("newtext.txt", "wb")
f.write(s[::-1])
f.close()
原始文件中的文本是:
This is Line 1
This is Line 2
This is Line 3
This is Line 4
当它反转并保存它时,新文件如下所示:
4 eniL si sihT 3 eniL si sihT 2 eniL si sihT 1 eniL si sihT
当我希望它看起来像这样时:
This is line 4
This is line 3
This is line 2
This is line 1
我怎样才能做到这一点?