第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

python中的文件迭代問(wèn)題

python中的文件迭代問(wèn)題

浮云間 2023-06-20 10:35:47
我有一個(gè)任務(wù),其中有兩個(gè)文件,即“user.txt”、“pwd.txt”,現(xiàn)在我想基本上遍歷這些文件的每個(gè)值,即“John”和“pwd.txt”中的所有值,然后是“user.txt”中的另一個(gè)值,所有值都是“pwd.txt”。這里我想實(shí)現(xiàn)線程。這是我的代碼,import threadingf1 = open("user.txt", "r")f2 = open("pwd.txt", "r")threads = []def brute():    for letter in f1.readlines():        print "[+]First Value: {}".format(letter)        for second_letter in f2.readlines():            print "[+]Second Value: {}".format(second_letter)                    threads.append(threading.Thread(target=runner, args=(letter,second_letter,)))for thread in threads:    thread.start()for thread in threads:    thread.join()    def runner(word1,word2):    print("[+]I am just a worker class: {0}:{1}".format(word1,word2))輸出來(lái)了[+]First Value: john[+]Second Value: test1234[+]Second Value: socool![+]Second Value: abcde1234[+]Second Value: password1[+]Second Value: Passw0rd[+]Second Value: adminRocks[+]First Value: dean[+]First Value: harry[+]First Value: sam[+]First Value: joseph[+]First Value: rick[+]I am just a worker class: john:test1234[+]I am just a worker class: john:socool![+]I am just a worker class: john:abcde1234[+]I am just a worker class: john:password1[+]I am just a worker class: john:Passw0rd[+]I am just a worker class: john:adminRocks[Finished in 0.3s]我不確定如何在此處使用密碼文件中的所有密碼打印所有用戶值。非常感謝任何幫助。
查看完整描述

1 回答

?
倚天杖

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超3個(gè)贊

根據(jù)您的帖子,目標(biāo)是交叉加入用戶和密碼文件。為此,在 pwd 文件中加載一次,然后處理每個(gè)用戶(每個(gè)線程一個(gè))。


請(qǐng)注意,我使用 Python 3.8 對(duì)此進(jìn)行了測(cè)試。


試試這個(gè)代碼:


import threading


# create files for testing

user = "user1\nuser2\nuser3\nuser4\nuser5\nuser6\nuser7\nuser8\nuser9"

pwd = "pwd1\npwd2\npwd3\npwd4\npwd5\npwd6\npwd7\npwd8\npwd9"

with open("user.txt",'w') as f: f.write(user)

with open("pwd.txt",'w') as f: f.write(pwd)



##### main script #####


# load all pwds

f2 = open("pwd.txt", "r")

lstpwd = f2.readlines()


f1 = open("user.txt", "r")

threads = []

def brute():

    for letter in f1.readlines():

        print ("\n[+]First Value: {}".format(letter.strip()))

        for second_letter in lstpwd:

            print ("[++]Second Value: {}".format(second_letter.strip()))

            threads.append(threading.Thread(target=runner, args=(letter,second_letter,)))


    for thread in threads:

        thread.start()


    for thread in threads:

        thread.join()

    

def runner(word1,word2):

    print("[+]I am just a worker class: {0}:{1}".format(word1.strip(),word2.strip()))

    

brute()

輸出


[+]First Value: user1

[++]Second Value: pwd1

[++]Second Value: pwd2

[++]Second Value: pwd3

.......    

[+]First Value: user2

[++]Second Value: pwd1

[++]Second Value: pwd2

[++]Second Value: pwd3

.......

[+]I am just a worker class: user1:pwd1

[+]I am just a worker class: user1:pwd2

[+]I am just a worker class: user1:pwd3

.......

[+]I am just a worker class: user2:pwd1

[+]I am just a worker class: user2:pwd2

[+]I am just a worker class: user2:pwd3

.......


查看完整回答
反對(duì) 回復(fù) 2023-06-20
  • 1 回答
  • 0 關(guān)注
  • 169 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)