当我运行服务器时,它返回一个IndexError
:“列表分配索引超出范围”。 由于我的文件rasp.py在第15行,但我没有找到原因。为什么我在运行Django项目时遇到IndexError?
rasp.py
#!/usr/bin/env python
def foo () :
tab= [ ]
i = 0
for i in range(12):
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)
mystring = mystr.replace(",",".")
tab [i] = mystring
return tab