while循环TypeError中出现零星的Python错误:“int”对象不是iterab

2024-06-09 22:51:05 发布

您现在位置:Python中文网/ 问答频道 /正文

以下是我的脚本中有错误的部分:

while:
    sensorIn = 8
    sensorOut = 5
    sensorAC = 7
    blue = 0
    white = 1
    [tempIn, humIn] = grovepi.dht(sensorIn, 1)
    print("tempIn = %.02f C humIn =%.02f%%"%(tempIn, humIn))
    [tempOut, humOut] = grovepi.dht(sensorOut, 1)
    print("tempOut = %.02f C humOut =%.02f%%"%(tempOut, humOut))
    [tempAC, humAC] = grovepi.dht(sensorAC, 1)
    print("tempAC = %.02f C humAC =%.02f%%"%(tempAC, humAC))

它会随机出错:

TypeError: 'int' object not iterable on the line: [tempAC, humAC] = grovepi.dht(sensorAC, 1)

它与树莓Pi和GrovePi板一起用于从温度和湿度传感器获取读数。它会循环,读取读数,然后用这些读数做一些事情,然后睡眠15分钟,然后再开始。你知道吗

也许while循环是个问题…我以前不使用while循环就运行这个程序,并且会在crontab中设置为每隔15分钟运行一次。有时一个读数会出错,但会以0的形式通过脚本,脚本不会停止并出错,它会继续通过并将值报告为0。你知道吗

我看了很多关于这个错误的帖子,但我只看到一些错误总是出现,并且根本不允许脚本在完成时运行,在我的例子中,它只是偶尔发生。你知道吗


Tags: 脚本错误print读数whiledhtgrovepitempin
1条回答
网友
1楼 · 发布于 2024-06-09 22:51:05

看来这是一个已知的问题grovepi.dht公司功能,有时可能由与设备的通信问题引起。http://forum.dexterindustries.com/t/incorrect-readings-and-typeerror/1582/2

解决方案只是为类型错误添加异常处理,因为这只是一个间歇性的问题(请参阅链接的文章以获取如何执行此操作的示例)。你知道吗

相关问题 更多 >