擅长:python、mysql、java
<p>您可以使用<code>readlines</code>读取数据,并使用列表理解来过滤<code>xxx</code></p>
<pre><code>ss = '''
Joe Smith
000000
Jeff Mitchell
xxxxxxx
Benjamin Grant
12346
'''.strip()
with open('names.txt','w') as f: f.write(ss) # write data file
###############################
with open('names.txt') as f:
lns = f.readlines()
xx = [ln.strip() for ln in lns if ln.strip() != 'xxxxxxx']
print('\n'.join(xx))
</code></pre>
<p>输出</p>
<pre><code>Joe Smith
000000
Jeff Mitchell
Benjamin Grant
12346
</code></pre>