首页 > 解决方案 > 如何比较两个字典“偶数触发器”的值

问题描述

我有将每秒更新的日志文件。我想读取该文件并每秒比较一次,因此如果第二列中的值发生更改,我将发送完整数据,否则我不做任何事情。

myDictionary:

    {'N': 'D_SPREADER_UNLOCKED_SIGNAL', 'T': '2019-09-20 10:01:27', 'V': '-1'}
    {'N': 'D_SPREADER_RIGHT_LANDED', 'T': '2019-09-20 10:01:27', 'V': '0'}
    {'N': 'C_SPREADER_45_FEET_SIGNAL', 'T': '2019-09-20 10:01:27', 'V': '0'}
    {'N': 'D_LOADCELL4', 'T': '2019-09-20 10:01:28', 'V': '416'}
    {'N': 'D_HOIST_POSITION_(MM)', 'T': '2019-09-20 10:01:28', 'V': '21391'}
    {'N': 'D_LOADCELL1', 'T': '2019-09-20 10:01:28', 'V': '608'}

import time
filepath=r"D:\python\Ram\data1.txt"
f = open(filepath, 'r')
rf=f.readlines()[1:][:-1]
f.close()
result={}
data1=[]
data2=[]
for row in rf:
    word1 = row.strip().replace("\t", ",").replace('\"', '').split(',')
    result={'N': word1[0],'T': word1[1], 'V': word1[2]}
    data1.append(result)

time.sleep(1)
for row in rf:
    word1 = row.strip().replace("\t", ",").replace('\"', '').split(',')
    result={'N': word1[0],'T': word1[1], 'V': word1[2]}
    data2.append(result)

#if column2 value data1 different from column2.value data send data 2 else pass

标签: python-3.x

解决方案


推荐阅读