簡體   English   中英

使用 For 循環比較打開文件中的兩行

[英]Comparing Two Lines In Opened Files With For Loops

好吧,這段代碼有效,但不是我想要的,如果有人能幫助我,我希望它取 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')

您需要 2 個嵌套循環:對於每一line ,遍歷所有line2 s:

with open('resolute','r') as renny:
    for line in renny:
        with open('ronny','r') as renna:
            for line2 in renna:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM