擅长:python、mysql、java
<p>首先你应该读入这个文件。这将为您提供文件中每一行的列表:</p>
<pre><code>with open('test.txt', 'rt') as file:
content = file.readlines()
</code></pre>
<p>现在,检查从每行最后一位到第二位的整数就足够了(去掉换行符后)。将其与5进行比较,然后将其写回文件,如下所示:</p>
<pre><code>with open('test.txt', 'wt') as file:
file.writelines([c for c in content if int(c.strip()[-2:]) >= 5])
</code></pre>