我想返回2个值:第一个是从连接到raspberry的传感器读取的数据,第二个是当前时间
rasp.py
#!/usr/bin/env python
from datetime import datetime
class ReturnValue(object):
__slots__ = ["x","y"]
def __init__(self,x,y):
self.x = x
self.y = y
def foo ( ) :
i = 0
for i in range(0,19):
i += 1
tfile = open("/sys/bus/w1/devices/28-000007101990/w1_slave")
text = tfile.read()
tfile.close()
secondline = text.split("\n")[1]
temp = secondline.split(" ")[9]
temperature = float(temp[2:])
temperature = temperature/1000
mystr = str(temperature)
y = mystr.replace(",",".")
x = datetime.datetime.now().time()
return ReturnValue(x, y)
答案 0 :(得分:0)
您没有正确缩进return
语句以及函数foo
中的第一行。