!curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/worl
d_temp_mean.csv -o mean_temp.txt
weather = open('mean_temp.txt','a+')
weather.write('Rio de Janeiro,Brazil,30.0,18.0\n"')
weather.seek(0)
headings = weather.readline()
apple = headings.split(',')
city_temp = weather.readline()
orange = city_temp.split(',')
while city_temp:
orange = city_temp.split(',')
print (apple[2] + ' of ' + orange[1] + ' is ' + orange[2] + ' Celsius')
city_temp = weather.readline()
weather.close()
のうちリストインデックスエラーが発生した理由を私は理解していない:分割とreadlineの - 範囲
list index out of range
が出力に。私は、whileループが文字列を受け取ることを保証するために、readlineとsplitを分離しようとしました。
あなたはエラートレースバックを投稿することもできます –
あなたの質問は低品質であることが示されており、査読者としてあなたに書いています。 (1)入力ファイル 'mean_temp.txt'の内容の一部を表示することができれば、あなたの質問に答えたい人には役に立ちます。 (2) 'apple'や' orange'のような名前を使うと、コードを読みにくくすることができます。たとえば、 'apple'では' heading_items'を代わりに使うことができます。 (3)私は@ KalyanReddyに同意します。 –