擅长:python、mysql、java
<pre><code>with open('a-file', 'r+') as f:
lines = []
for line in f:
if line.strip().isdigit():
line = line.rstrip() + '\t\t\n'
lines.append(line)
f.seek(0)
f.writelines(lines)
</code></pre>
<p><a href="http://docs.python.org/3/library/stdtypes.html#str.isdigit" rel="nofollow">str.isdigit()</a></p>
<p>正则表达式替代:<code>if re.search('^\d+$', line) != None</code></p>