配置比对脚本(python)
2024-10-12 03:48:04
# -*- coding: utf- -*- from datetime import * import MySQLdb import sys import time import datetime import json import logging logging.basicConfig(level=logging.INFO, format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s', datefmt='%a, %d %b %Y %H:%M:%S', filename='tb_test004.log', filemode='w') console = logging.StreamHandler() console.setLevel(logging.INFO) formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') console.setFormatter(formatter) logging.getLogger('').addHandler(console) def process(): dict1 = {} file1 = open("newlogic52.txt") : line = file1.readline() if not line: break arr_line = line.split( ); : #logging.info(arr_line[]) #logging.info(arr_line[]) key = arr_line[] value = arr_line[] dict1[key] = value else: continue logging.info("-------------------------") dict2 = {} file2 = open("oldlogic52.txt") : line = file2.readline() if not line: break arr_line = line.split( ); : #logging.info(arr_line[]) #logging.info(arr_line[]) key = arr_line[] value = arr_line[] dict2[key] = value else: continue f = file("hello3.txt","w+") logging.info("************************") sume = for key1 in dict1: #logging.info(key1) #logging.info(dict1[key1]) for key2 in dict2: # logging.info(key2) # logging.info(dict2[key2]) if key1.strip() == key2.strip() and dict1[key1].strip() != dict2[key2].strip(): li1 = "new key:%s , value: %s \n" % (key1,dict1[key1]) #logging.info(li1) li2 = "old key:%s , value: %s \n" % (key2,dict2[key2]) #logging.info(li2) if key1.strip() == key2.strip() and dict1[key1].strip() == dict2[key2].strip(): sume = sume + if key1.strip() == key2.strip() and dict1[key1].strip() == dict2[key2].strip(): li1 = "%s=%s\n" % (key1.strip(),dict1[key1].strip()) f.writelines(li1) f.close() dict3 = {} file3 = open("hello3.txt") : line = file3.readline() if not line: break arr_line = line.split( ); : #logging.info(arr_line[]) #logging.info(arr_line[]) key = arr_line[] value = arr_line[] dict3[key] = value else: continue for key2 in dict2: # logging.info(key2) # logging.info(dict3[key2]) if dict3[key2] == None: logging.info(key2) logging.info("@@@@@@@@@@@@@@@@@@@@@@@@@@") logging.info(sume) logging.info("new %s" % len(dict1)) logging.info("old %s" % len(dict2)) logging.info("same %s" % len(dict3)) if __name__ == "__main__": process()
最新文章
- c# socket 编程
- svn的牛逼操作反向merge
- [UCSD白板题] Covering Segments by Points
- 【C#进阶系列】14 字符、字符串和文本编码
- 关于xcode不同版本打开相同工程问题
- Kafka 消息监控 - Kafka Eagle
- 设置groupBox背景透明
- 关于Servlet会话跟踪的那些事儿
- MyBatis 源码分析——动态SQL语句
- ie8兼容background-size属性
- CubieBoard开发板不用ttl线也不用hdmi线的安装方法
- IDLE3.6.3 Mac版不支持中文输入解决办法
- oAuth2授权协议 &; 微信授权登陆和绑定 &; 多环境共用一个微信开发平台回调设置
- dbms_redefinition在线重定义表结构
- 装饰者模式在JDK和Mybatis中是怎么应用的? java io包
- java限制map大小,并FIFO淘汰
- 内置函数二(lambda函数,sorted(),filter(),map(),递归函数,二分法查找)
- UML类建模(强烈推荐-思路很清晰)
- mysql命令行各个参数解释
- python 安装包
热门文章
- coreseek增量索引合并
- ORM之殇,我们需要什么样的ORM框架?
- unsilder中的jq深入学习
- UnicodeEncodeError: 'ascii' codec can't encode characters in position 820-823: ordinal not in range(128)
- Linux及VMWare的网卡选择设计及理解
- ThinkPHP 隐藏URL中的 index.php
- meta_value与meta_value_num的区别(排序)
- 光驱SSD安装Win7+ubuntu系统双系统
- How to Delete XML Publisher Data Definition Template
- Python中模块安装文件的创建及使用