【发布时间】:2025-12-27 05:55:17
【问题描述】:
我有一个正在读取的文件
fo = open("file.txt", "r")
然后通过做
file = open("newfile.txt", "w")
file.write(fo.read())
file.write("Hello at the end of the file")
fo.close()
file.close()
我基本上是将文件复制到一个新的,但也在新创建的文件末尾添加一些文本。我怎么能插入那条线,说,在由空行分隔的两行之间?即:
line 1 is right here
<---- I want to insert here
line 3 is right here
我可以用\n 之类的分隔符来标记不同的句子吗?
【问题讨论】:
标签: python io insert tokenize writetofile