回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我想在<code>output1_file</code>中从<code>input_file</code>写入行,但当我运行程序时,它不会将第一行写入输出文件。你知道吗</p>
<pre><code>import csv
from statistics import mean
from typing import TextIO
def calculate_averages(input_file_name, output_file_name):
with (open(input_file_name, 'r')) as fin:
line=fin.readline()
while line:
line = fin.readline()
with open (output_file_name,'a') as f:
f.write((line.strip()))
f.write('\n')
f.close()
line = fin.readline()
return f
calculate_averages('input.csv', 'output1.csv')
</code></pre>
<p>我的输入文件是:</p>
<pre><code>mandana,5,7,3,15
hamid,3,9,4,20,9,1,8,16,0,5,2,4,7,2,1
sina,19,10,19,6,8,14,3
sara,0,5,20,14
soheila,13,2,5,1,3,10,12,4,13,17,7,7
ali,1,9
sarvin,0,16,16,13,19,2,17,8
</code></pre>
<p>但我的输出文件是:</p>
<pre><code> hamid,3,9,4,20,9,1,8,16,0,5,2,4,7,2,1
sina,19,10,19,6,8,14,3
sara,0,5,20,14
soheila,13,2,5,1,3,10,12,4,13,17,7,7
ali,1,9
sarvin,0,16,16,13,19,2,17,8
</code></pre>
<p>第一行不见了。你知道吗</p>