Python在结构数组中指定不同的日期时间

Python在结构数组中指定不同的日期时间,python,datetime,struct,for-in-loop,namedtuple,Python,Datetime,Struct,For In Loop,Namedtuple,如果捕获值中的DeviceInfo列表数组为TRUE,同时Datetime与Datetime不同。现在大于5秒。那么打印真,怎么做呢 p/s:捕获正确且datetime大于5秒,必须是相同的数组索引 import struct from collections import namedtuple StructDeviceInfo = namedtuple('DeviceInfo', ['DeviceID', 'Capturing','Receiving','Socket','DateTime'

如果捕获值中的DeviceInfo列表数组为TRUE,同时Datetime与Datetime不同。现在大于5秒。那么打印真,怎么做呢

p/s:捕获正确且datetime大于5秒,必须是相同的数组索引

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')
应用于您的示例,假设
x.Datetime
实际上是一个
Datetime.Datetime
对象:

delta = datetime.datetime.now() - x.Datetime
if delta.total_seconds() > 5:
    # difference is greater than 5 seconds 

不,我更喜欢在这样的句子方法中使用,例如,如果有的话(x.Capturing==True,适用于DeviceInfo列表中的x)和(x.Datetime,适用于DeviceInfo列表中的不同秒数>5)@C.Y:应用起来很简单,不是吗?我刚刚向您展示了如何使用
timedelta
对象的语义。还有,您的x来自哪里?@C.Y:您的
x
来自同一个地方。抱歉,答案不能让我理解如何在这样的句子中实现(x.Datetime在DeviceInfo列表中不同秒>5)
if any((
        x.Capturing == True and 
        (datetime.datetime.now() - x.Datetime).total_seconds() > 5
       ) for x in DeviceInfoList):