擅长:python、mysql、java
<p>这是我评论中一个未经测试的快速示例。通过在找到名称后从0开始计数,可以在找到匹配项后排除n行</p>
<pre><code>def delete_someone():
Y=input("Enter the full name:")
archivo=open("agenda.txt", "r")
count_lineas= archivo.readlines()
archivo.close()
archivo1= open("agenda.txt", "w")
delete_counter = float('inf') # This can be any number above 2 to be honest
for line in count_lineas:
if line.strip("\n") == Y:
delete_counter = 0 # Restart the counter
if delete_counter > 2: # Skip the next 2 lines too
archivo1.write(line) # Write the 3rd line onwards
delete_counter += 1
archivo1.close()
</code></pre>
<p>这不是最有效或最奇特的解决方案,它只是简单易懂的东西</p>