我的Python数据代码保存温度传感器(DS18B20)的数据,但不会将温度保存在列中。温度是这样写的:'25.25‘。有没有人能告诉我怎么修。我必须将传感器的读数温度分成几个数字。谢谢你的帮忙
while programmStatus == 1:
#while True:
now = datetime.now(timezoneBerlin)
#while True:
# open new file
with open ( 'test.tsv', 'w') as f:
for temperature_single in Temperature:
f.write ("{:>5}\n".format('Temperature'))
f.write("\t{:>5}\n".format
(format(temperature_single)))
f.write("\n")
f.flush()
f.close()
x = 0
ds1820readout()
print ("Sensorname und Temperaturevalue:")
while x < tempSensorQuantity:
print (tempSensorName[x] , " " , tempSensorValue[x], " °C")
x = x + 1
print ("\n")在这段代码中,关闭的文件有一个I/O错误,有没有人能帮忙?
发布于 2020-09-02 02:41:26
似乎温度是一个值列表。如果您尝试将它们放入csv中,则必须首先迭代列表,例如:
tempSensorName = []
tempSensorQuantity = 0
tempSensorValue = []
programmStatus = 1
Temperature = tempSensorValue
def ds1820einlesen():
global tempSensorName, tempSensorQuantity, programmStatus
def ds1820auslesen():
global tempSensorName, tempSensorQuantity, tempSensorValue,
with open ( 'test.tsv', 'w') as f:
for temperature_single in Temperature:
f.write ("{:>5}\n".format('Temperature'))
f.write("\t{:>5}\n".format(format(temperature_single)))
f.write("\n")
f.flush()
f.close()
x = 0
ds1820auslesen()
print ("Sensorname and Temperaturevalue:")
while x < tempSensorQuantity:
print (tempSensorName[x] , " " ,
tempSensorValue[x], " °C")
x = x + 1
print ("\n")https://stackoverflow.com/questions/63548459
复制相似问题