Python比较两个文件不同之处

Python比较两个文件不同之处

𝓓𝓸𝓷 Lv6

Python比较两个文件不同脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env python



file1_name = '/tmp/fea2.txt'
file2_name = '/tmp/lic0920.lic'

data1 = []
data2 = []


with open(file1_name, 'r') as f1, open(file2_name, 'r') as f2:
for i in f1.readlines():
data1.append(i.strip().lower())

for j in f2.readlines():
if 'INCREMENT' not in j:
continue
data2.append(j.strip().lower().split()[1])


result = [ i for i in data1 if i not in data2 ]

for i in result:
print i

  • Title: Python比较两个文件不同之处
  • Author: 𝓓𝓸𝓷
  • Created at : 2024-07-16 18:30:36
  • Updated at : 2025-04-27 15:07:40
  • Link: https://www.zhangdong.me/python-compare-file-differences.html
  • License: This work is licensed under CC BY-NC-SA 4.0.
评论