input()的内容如何插入到文本文档指定位置

input()的内容无法保存到txt文档中,且重新生成的txt文件为空白文档

with open("条款.txt","r") as file:
content = file.read()
count = len(open(r"条款.txt",'r').readlines())
print(count)

email_address = input("请输入供应商邮箱:")
1#(str = abcd@def.com)

keyword="卖方: "
post = content.find(keyword)
if post != -1:
content = content[:post+len(keyword)]+email_address+content[post+len(keyword):]
2# ( content = content[:post+len(keyword)]+str+content[post+len(keyword):])

file1 = open(r"条款2.txt",'w')
file1.write(content)
单独使用 1#和2#处的代码时,新生成的条款可以在准确的位置(即卖方:)后方插入邮箱,但是如果使用粗体的input()代码时,条款2的内容是空白的。

如果你是要追加到最后,那么把w改为a+
如果你是要插入任意位置,那只能把文件里的数据先读取出来,插入,再重新写回去
文件在硬盘里是连续存储的,磁带你见过吧,你胡乱往里面写东西会覆盖掉原来的数据

指针