對於我正在做的任務,我需要破解一個鎖定的PDF文件。我正在嘗試創建一個密碼列表以便這樣做,但無法解決如何將此代碼生成的結果輸出到文本文件中。輸出到文本文件Python 2.7
from random import shuffle
with open('randomwords.txt', 'r') as data:
data = data.read().split()
while(True):
shuffle(data)
password = ''
for x in data[:3]:
password += x
print password.replace('o','0')
一切我已經試過到目前爲止還沒有工作,將不勝感激,如果有人能告訴我如何輸出的結果此代碼生成到外部文本文件。
變換溫控功能:
def transform(word):
from random import shuffle
with open('randomwords.txt', 'r') as data:
data = data.read().split()
while(True):
shuffle(data)
password = ''
for x in data[:3]:
password += x
print password.replace('o','0')
return word
那麼它好像你知道如何打開一個文件,所以以寫模式打開一個文件,而不是打印,寫入該文件。你也有一個無限循環,如果你正在寫一個文件,這會很糟糕... – MooingRawr
http://www.pitt.edu/~naraehan/python2/reading_writing_methods.html –
什麼結果需要寫入外部文件?你沒有任何結果 –