使用 For 循环比较打开文件中的两行
Comparing Two Lines In Opened Files With For Loops
好的,伙计们,这段代码有效,但不是我想要的,如果有人能帮忙,我希望它在 hash_replace 中获取第一行并检查 hash_found 中的每一行,直到找到一个,但此代码只是将它们并排比较 side.If 如果有人能提供帮助,我将不胜感激。
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
:
with open('resolute','r') as renny:
for line in renny:
with open('ronny','r') as renna:
for line2 in renna:
好的,伙计们,这段代码有效,但不是我想要的,如果有人能帮忙,我希望它在 hash_replace 中获取第一行并检查 hash_found 中的每一行,直到找到一个,但此代码只是将它们并排比较 side.If 如果有人能提供帮助,我将不胜感激。
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
:
with open('resolute','r') as renny:
for line in renny:
with open('ronny','r') as renna:
for line2 in renna: