python-3.x - 如何比较两个字典“偶数触发器”的值
问题描述
我有将每秒更新的日志文件。我想读取该文件并每秒比较一次,因此如果第二列中的值发生更改,我将发送完整数据,否则我不做任何事情。
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
解决方案
推荐阅读
- apache-spark - 如何在 pyspark 的 For 循环中插入自定义函数?
- django-rest-framework - 使用 ComplexFilterBackend 从 django-rest-framework-filters 中的 URL 排序(排序)
- sql - 用于在 localhost 上开发但使用服务器数据库的 Wordpress Ubuntu 数据库 wp_options 解决方法
- blazor - 如何从文件夹运行已发布的 Blazor Web 客户端?
- javascript - 拖动时是否可以更改自动滚动偏移量?
- linux - 如何在 Assembly 中创建并直接写入文本控制台缓冲区
- java - 启动应用程序时的进程顺序
- python - 如何减少 Python 中的 Plotly HTML 大小?
- java - 如何在 java 中创建 JSONArray
- ms-wopi - MS WOPI:当 ppt 文件在一段时间后打开进行编辑时显示使用这些帐户之一登录