擅长:python、mysql、java
<p>filemode<code>"w"</code>在每个步骤中创建一个新的空文件。使用模式<code>"a"</code>进行追加,或者将打开的文件移到循环之外。在</p>
<pre><code>with open("russ.txt", "r") as f:
for line in f:
line = line.split()
line = line[-1]
if line == "Ticker": continue
print line
with open("output.txt", "a") as fh:
fh.write(line + "\n")
</code></pre>
<p>或者最好只打开一次文件:</p>
^{pr2}$