问答详情
源自:6-5 Python把字符串写入文件

参考答案是错误的,没有考虑换行符

OpenFile = open("source.txt","r")
lines = OpenFile.readlines()
CreateFile = open("target.txt","w")
for i in lines:
    Ri = i[::-1]
    if lines.index(i) == -1:
        break
    Ri = Ri.strip()
    Ri = Ri+"\n"
    CreateFile.write(Ri)
OpenFile.close()
CreateFile.close()

提问者:weixin_慕前端1126109 2022-04-25 16:44

个回答

  • qq_慕婉清6326688
    2022-07-18 17:39:51

    确实如此