Pergunta

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

if the DeviceInfoList array inside the Capturing Value is TRUE and at the same time the Datetime are different with datetime.now are more than 5 second. then print true,how to do this?

p/s:the Capturing is TRUE and datetime is more than 5 seconds,must be same array index .

Foi útil?

Solução

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

Applied to your example, assuming that x.Datetime actually is a datetime.datetime object:

if any((
        x.Capturing == True and 
        (datetime.datetime.now() - x.Datetime).total_seconds() > 5
       ) for x in DeviceInfoList):
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top