[英]Save Data in a Column Python DS18B20
我的 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/0 错误,有人可以帮忙吗?
似乎温度是一个值列表。 如果您尝试将它们放入 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")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.