擅长:python、mysql、java
<pre><code>with open('/path/to/read/txt','r') as f:
l=f.readlines()
l1=[" ".join(i.partition('MIN')[1::]).strip(' ') for i in l ]
f1=open('/path/to/write/txt','w')
for i in l1:
f1.write(i)
f1.close()
</code></pre>
<p>您可以在字符串列表上使用<code>partition</code>方法</p>
<p><a href="https://docs.python.org/3/library/stdtypes.html#str.partition" rel="nofollow noreferrer">str.partition(sep)</a></p>
<blockquote>
<p>Split the string at the first occurrence of sep, and return a 3-tuple
containing the part before the separator, the separator itself, and
the part after the separator.</p>
</blockquote>
<pre><code>[('Rahul', 'MIN', ' Y(03). \n')........]
</code></pre>
<p>您只需将最后两个元组(即从<code>MIN</code>)连接起来,然后使用<code>join</code>构建一个新字符串</p>