【发布时间】:2016-01-05 12:00:42
【问题描述】:
我想做下面的函数来存储all_tmp和all_date数据并在以后使用。这就是我所拥有的......
def temperature(temp_file):
'''
This is a function that loads temperature data
from WeatherUnderground. Type in the following:
temperature('filename.filetype')
'''
file_obj=open(temp_file)
all_dates=[]
all_tmps=[]
for line in file_obj:
words=line.split(',')
try:
dates=parse(words[0])
tmps=float(words[1])
all_dates.append(dates)
all_tmps.append(tmps)
except (ValueError,IndexError):
pass
file_obj.close()
tempDat= return(all_dates,all_tmps) # This is supposed to store the variables...
(all_dates,all_tmps) = temperature(temp_file)
我想在单独的脚本中打开我的每个函数并绘制它们...但是我的变量(all_dates 和all_tmps)不会存储。我是不是缩进错了?
【问题讨论】:
-
我不清楚你到底在问什么。你知道如何
import一个模块吗?这似乎是第一个开始的地方。 -
@Blckknght... 我改变了我需要做的事情。我的第一个障碍是让我的变量实际存储。我不知道存储它们需要什么语法。我读过其他帖子,但都没有那么有用。
-
tempDat= return(all_dates,all_tmps) 有什么用?您收到无效的语法消息吗?。
-
我没有得到无效的语法......这是我保存变量的许多绝望尝试之一。我认为这是错误的。