-2
!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
。我试图分开readline和split,以确保while循环只接收字符串。
你也可以发布错误追溯 –
你的问题已被标记为低质量,我写信给你作为审稿人。 (1)如果你能显示输入文件的一些内容,“mean_temp.txt”,那么任何想回答你的问题的人都会很有帮助。 (2)使用像“apple”和“orange”这样的名字会让你的代码难以阅读。例如,对于'apple',你可以使用'heading_items'来代替。 (3)我同意@KalyanReddy。 –