我有以下形式的 2 个文件:
file1:
work1
7 8 9 10 11
1 2 3 4 5
6 7 8 9 10
file2:
work2
2 3 4 5 5
2 4 7 8 9
work1
7 8 9 10 11
1 2 4 4 5
6 7 8 9 10
work3
1 7 8 9 10
现在我想与文件进行比较,并且无论标题(work1)是否相等..我想比较后续部分并打印发现差异的行。例如
work1 (file1)
7 8 9 10 11
1 2 3 4 5
6 7 8 9 10
work1 (file2)
7 8 9 10 11
1 2 4 4 5
6 7 8 9 10
现在我想打印出现差异的行,即“1 2 4 4 5”
为此,我编写了以下代码:
with open("file1",) as r, open("file2") as w:
for line in r:
if "work1" in line:
for line1 in w:
if "work1" in line1:
print "work1"
但是,从这里开始,我对如何同时读取这两个文件感到困惑。有人可以帮我解决这个问题...因为在比较“work1”之后我没有得到我应该如何并行读取文件