zoukankan      html  css  js  c++  java
  • python文件对比

     1 #-*- encoding:utf-8 -*-
     2 
     3 class loadDatas(object):
     4     def __init__(self):
     5         self.path='./data'
     6     def load_compare(self):
     7         l1={}
     8         f1=open(self.path+'/95b.txt',encoding='utf-8')
     9         l2={}
    10         f2=open(self.path+'/05b.txt',encoding='utf-8')
    11         f=open(self.path+'/1.txt','a')
    12         # w2=open('./data/1.txt','a')
    13 
    14             # flag=1
    15         str1=[]
    16         # print(type(str1))
    17         # int i
    18         for line2 in f2:
    19             print(line2)
    20             (tag2,name)=line2.strip().split("  ")
    21             flag=0
    22             for line1 in f1:
    23             # 读完一次循环后,line1已经到底了,第2次循环便不进入;
    24             # f1.readlines()只能进入一次,一次读取整个文件;
    25             
    26                 (tag1,name)=line1.strip().split("  ")
    27                 print(tag1)
    28                 if tag2==tag1:
    29                     print("a")
    30                     flag=0
    31                     break
    32                 else:
    33                     print('d')
    34                     flag=1
    35                     # break
    36             # print("aa")
    37             if flag==1:
    38                 # print("aa")
    39                 str1.append(line2)
    40             f1.seek(0)
    41         print(str1)
    42         f.writelines(str1)   
    43 
    44         f1.close()
    45         f2.close()
    46         f.close() 
    47   
    48 if __name__=='__main__':
    49     ld=loadDatas()
    50     ld.load_compare()
  • 相关阅读:
    python安装
    实现node服务器
    VSCode集成tomcat及使用方法
    CommonJS规范
    Bootstrap 笔记
    vue笔记
    jgGrid模板添加
    vue组件中的data
    解析DNS
    StaticResource
  • 原文地址:https://www.cnblogs.com/smuxiaolei/p/7405311.html
Copyright © 2011-2022 走看看