import struct
from collections import namedtuple
StructDeviceInfo = namedtuple('DeviceInfo', ['DeviceID', 'Capturing','Receiving','Socket','DateTime'])
DeviceInfoList = []
def threaded_function():
while True:
if any(x.Capturing == True and x.Datetime in DeviceInfoList different second > 5 for x in DeviceInfoList) : #here,how to do on here?
print('True')
如果捕获值内的DeviceInfoList数组为TRUE,同时Datetime与Datetime.now不同,则超过5秒。那么打印真的,怎么做呢?
p/s:Capturing为TRUE,且日期时间超过5秒,必须是相同的数组索引。
delta = datetime.datetime.now() - x.Datetime
if delta.total_seconds() > 5:
# difference is greater than 5 seconds
应用于您的示例,假设x.Datetime
实际上是datetime.datetime
对象:
if any((
x.Capturing == True and
(datetime.datetime.now() - x.Datetime).total_seconds() > 5
) for x in DeviceInfoList):