比较带有For循环的已打开文件中的两行

问题描述 投票:0回答:1

[好吧,这些代码可以工作,但是不是我想要的,如果有人可以帮助我希望它使用hash_replace的第一行并检查hash_found中的每一行,直到找到一个,但是此代码只是将它们并排比较如果有人能帮助我,我将不胜感激。

with open('resolute','r') as renny:
    with open('ronny','r') as renna:
        for line,line2 in zip(renny,renna):
            lin = line.split()
            li = line2.split()
            hash_to_replace = lin[2]
            email = lin[0]
            hash_found = li[0]
            pass_found = li[2]
            if hash_to_replace == hash_found:
                print('Found')
            else:
                print('Nothing')
python loops file-handling readlines
1个回答
1
投票

您需要2个嵌套循环:对于每个line,循环遍历所有line2

with open('resolute','r') as renny:
    for line in renny:
        with open('ronny','r') as renna:
            for line2 in renna:
© www.soinside.com 2019 - 2024. All rights reserved.