擅长:python、mysql、java
<p>Python提供了一个模块<a href="https://docs.python.org/3/library/fileinput.html" rel="nofollow">fileinput</a>,它对于此任务特别方便:</p>
<pre><code>import fileinput
import sys
count = 0
for line in fileinput.input([filename], inplace=True, backup='.bak'):
if line.startswith('QA'):
pre, post = line.rsplit(',', 1)
sys.stdout.write('{},{:0.1f}\n'.format(pre, count))
count += 0.2
else:
sys.stdout.write(line)
</code></pre>
<hr/>
<p>我认为在用递增0.2的数字替换<code>0.0</code>之前,不需要将所有<code>1.0</code>替换为<code>0.0</code>。相反,只需找到以<code>QA</code>开头的行,并用所需的数字替换最后一个数字。在</p>