0
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')

如果 Capturing Value 中的 DeviceInfoList 数组为 TRUE,同时 Datetime 与 datetime.now 不同,则超过 5 秒。然后打印真实,如何做到这一点?

p/s:Capturing 为 TRUE 且 datetime 大于 5 秒,必须是相同的数组索引。

4

1 回答 1

1
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):
于 2013-02-07T10:20:33.660 回答