擅长:python、mysql、java
<p>这就是你想要的:</p>
<pre><code>text = "Can you hear me?"
with open("input.txt", "r") as infile:
readcontent = infile.readlines()
with open("output.txt", "w") as out_file:
for idx,line in enumerate(readcontent):
if line.rstrip() == text:
line+='\nAdded new line\n\n'
out_file.write(line)
</code></pre>
<p><code>output.txt</code>看起来像:</p>
<pre><code>ricochet robots
settlers of catan
acquire
Hi! How are you?
Can you hear me?
Added new line
this is very valuable
finish
</code></pre>