Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python计算机编程。代码应该从文本文件读入数据_Python_Weather - Fatal编程技术网

Python计算机编程。代码应该从文本文件读入数据

Python计算机编程。代码应该从文本文件读入数据,python,weather,Python,Weather,现在我正试图编写一个代码,从URL文件中获取数据,计算平均温度。文件读取正确(我为“d”做了一个打印语句,所有内容都在那里),但在那之后,所有内容似乎都停止了工作 该文件有4列(按此顺序):日、月、年和温度。 因为我想计算平均温度,所以我只需要最后一列,但我试图首先定义所有列,因为我需要能够找到每年的平均温度 我真的希望你能帮上忙,我已经为此工作了好几个小时了,但一直没有进展 这是我当前代码的开头 local_file='str(station)' infile = open(local_fil

现在我正试图编写一个代码,从URL文件中获取数据,计算平均温度。文件读取正确(我为“d”做了一个打印语句,所有内容都在那里),但在那之后,所有内容似乎都停止了工作

该文件有4列(按此顺序):日、月、年和温度。 因为我想计算平均温度,所以我只需要最后一列,但我试图首先定义所有列,因为我需要能够找到每年的平均温度

我真的希望你能帮上忙,我已经为此工作了好几个小时了,但一直没有进展

这是我当前代码的开头

local_file='str(station)'
infile = open(local_file, 'r')
d=infile.readlines()
data = {}
data['data'] = {}
#defines each column with an actual variable name
for line in infile:
  columns = line.split()
  print columns
  month = int(columns[0])
  day = int(columns[1])
  year = int(columns[2])
================================================


提前感谢您的帮助。我真的很感激任何建议

删除行
d=infle.readlines()
或使用
d
进入for循环
infle

站点定义为什么?是否需要str?由于本地_文件被设置为str(station),所以不清楚问题是什么?这篇文章的标题很糟糕,没有告诉我们你正在努力解决什么问题。但话说回来,《华盛顿邮报》本身也是如此。