如何尝试文件中的行是否与 Python 中的其他文件中的行匹配
How to try if lines in a file match with lines in an other file in Python
如何 "brute" 文件中的每一行直到找到匹配的内容,我的意思是我将 save.data
和 brute.txt
中的每一行都变成了两个列表(对于易于访问),这里是 brute.txt
:
username
username1
password
password1
这里是save.data
(因为这是一个批处理文件游戏,所以不需要引用像"username1"这样的字符串):
username1 = PlayerName
password1 = PlayerPass
所以,我的要求是,我想尝试 brute.txt
中的第 1 行是否与 save.data
(即 'username1')中等号之前的内容匹配,如果它与它不匹配传递到下一行,依此类推,直到它到达文件末尾(save.data
)然后尝试如果来自 brute.txt
的第 2 行与来自 save.data
的第 1 行匹配(匹配)如果不匹配,如果 brute.txt
中的第 2 行匹配 save.data
中第 2 行中的限定符号之前的内容,依此类推......最后,当 "username" 匹配时"username",用save.data
中等号后面的值创建一个名为username
的变量。因此,当 "bruting" 过程完成后,我必须有两个变量,一个是 username = PlayerName
另一个是 password = PlayerPass
以供进一步使用。我尝试了 while、for 和 try 循环,但我卡住了,因为这样做我需要知道 save.data
.
中的内容
-如果你有什么不明白的地方,请评论,我会解决的。
可能有更有效的方法来做到这一点,但要回答您提出的问题..
首先打开save.data
文件并将内容读入列表:
with open('save.data') as fp:
save_data = [line.split(' = ') for line in fp.read().splitlines()]
对 brute.txt
文件执行相同的操作:
with open('brute.txt') as fp:
brute = fp.read().splitlines()
然后遍历用户名和密码:
for username, password in save_data:
if username in brute:
break
else:
print("didn't find the username")
for-loop 中的 username
和 password
变量在 for-loop 中断后将具有正确的值。
(请注意 else:
在 for-loop 上,而不是 if..)
如何 "brute" 文件中的每一行直到找到匹配的内容,我的意思是我将 save.data
和 brute.txt
中的每一行都变成了两个列表(对于易于访问),这里是 brute.txt
:
username
username1
password
password1
这里是save.data
(因为这是一个批处理文件游戏,所以不需要引用像"username1"这样的字符串):
username1 = PlayerName
password1 = PlayerPass
所以,我的要求是,我想尝试 brute.txt
中的第 1 行是否与 save.data
(即 'username1')中等号之前的内容匹配,如果它与它不匹配传递到下一行,依此类推,直到它到达文件末尾(save.data
)然后尝试如果来自 brute.txt
的第 2 行与来自 save.data
的第 1 行匹配(匹配)如果不匹配,如果 brute.txt
中的第 2 行匹配 save.data
中第 2 行中的限定符号之前的内容,依此类推......最后,当 "username" 匹配时"username",用save.data
中等号后面的值创建一个名为username
的变量。因此,当 "bruting" 过程完成后,我必须有两个变量,一个是 username = PlayerName
另一个是 password = PlayerPass
以供进一步使用。我尝试了 while、for 和 try 循环,但我卡住了,因为这样做我需要知道 save.data
.
-如果你有什么不明白的地方,请评论,我会解决的。
可能有更有效的方法来做到这一点,但要回答您提出的问题..
首先打开save.data
文件并将内容读入列表:
with open('save.data') as fp:
save_data = [line.split(' = ') for line in fp.read().splitlines()]
对 brute.txt
文件执行相同的操作:
with open('brute.txt') as fp:
brute = fp.read().splitlines()
然后遍历用户名和密码:
for username, password in save_data:
if username in brute:
break
else:
print("didn't find the username")
for-loop 中的 username
和 password
变量在 for-loop 中断后将具有正确的值。
(请注意 else:
在 for-loop 上,而不是 if..)