python - 将数据保存在列中 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")
推荐阅读
- gps - 在 JS 中获取准确定位数据的最佳方法
- python - 使用 Python 根据另一列上的类别将一列切割成分位数
- apache - 简单的重写规则在 Apache 服务器上不起作用
- vba - 通过 VBA 连接到 SQL Server
- java - 如何在 Java 中查找完整 JSON 文档中的所有匹配值
- pytorch - ValueError:使用 RNN 分类器解包的值太多(预期为 2)
- c# - 如何在 ASP.net Core 中创建“装饰器缩写”
- java - SurfaceView.OnAttachedToWindow 中的 NullPinterException
- discord.js - 我希望我的 Discord Bot 将用户在命令中写入的消息发送到另一个频道 -js
- nginx - Google Lighthouse NGINX 性能问题