我有这段代码,它运行两次正常,而在第三次调用时我得到一个错误,就好像我会通过时间戳一样。我只通过元组或无。
from pprint import pprint
from gpiozero import RGBLED
def signal(pri, newcolor):
signal.priority[pri] = newcolor
pprint(signal.priority)
try: signal.led.color = next(color for color in signal.priority if color is not None)
except StopIteration: signal.led.color = (0,0,0)
signal.led = RGBLED(red=11, green=9, blue=10)
signal.priority = 2*[None]
输出如下
[None, (0, 1, 0)]
[None, (0, 0, 1)]
[None, (1, 1, 0)]
Traceback (most recent call last):
File "/home/pi/zrcrasp.py", line 137, in <module>
signal(1, (1,1,0))
File "/home/pi/zrcrasp.py", line 10, in signal
try: signal.led.color = next(color for color in signal.priority if color is not None)
TypeError: 'Timestamp' object is not callable
背景
程序的各个部分使用该函数来表示任何类型的错误,但如果高优先级的红色短闪结束,则较低优先级的绿色应继续。如果没有低优先级 - None
,则 led 将被关闭(这是except
用于的语句)
最低索引是最高优先级。