我對Python非常陌生,並且創建了一個小密碼破解程序,它使用強力攻擊,我試圖讓程序運行時輸出進度條,這裏是什麼我至今:使用進度條輸出
import zipfile
import sys
import time
def progress_bar(sleep_time):
for i in range(101):
time.sleep(sleep_time)
sys.stdout.write("\r[{0}] {1}%".format('#'*(i/10), i))
sys.stdout.flush()
def obtain_password(path_to_zip_file):
password = None
zip_file = zipfile.ZipFile(path_to_zip_file)
with open('wordlist.txt', 'r') as dict:
for line in dict.readlines():
possible = line.strip("\n")
try:
zip_file.extractall(pwd=possible)
password = "Password found {}".format(possible)
except:
pass
return password
所以我的問題是如何才能得到進度條輸出,而obtain_password
方法運行?我是否需要稍微改變一下進度條方法?
你可以嘗試有進度條和另外一個一個線程用於'gets_password'函數。 http://www.tutorialspoint.com/python/python_multithreading.htm或者你可以使'gets_password'函數稍微畫一下進度條。 – grael
@grael在這一點上,對於我來說這似乎有點進步,我喜歡它,謝謝。 –