import os
import sys
import fileinput
import random
import string
stringLength=10
"""Generate a random string of fixed length """
letters = string.ascii_lowercase
Password = ''.join(random.choice(letters) for i in range(stringLength))
print ("Text to search for:")
textToSearch = input( "> " )
print ("File to perform Search-Replace on:")
fileToSearch = input( "> " )
tempFile = open( fileToSearch, 'r+' )
for line in fileinput.input( fileToSearch ):
if textToSearch in line :
print('Match Found')
else:
print('Match Not Found!!')
tempFile.write( line.replace( textToSearch, Password ) )
tempFile.close()
input( '\n\n Press Enter to exit...' )
这是发生了什么
start /min MinecraftClient.exe qQ47n2 - mc.cosmicmc.com
start /min MinecraftClient.exe qQ47n2 - mc.cosmicmc.com
start /min MinecraftClient.exe qQ47n2 - mc.cosmicmc.com
qQ47n2正在发生变化 我希望每行都是随机的,但正如您所见,每行向下都有qQ47n2吗?
有什么想法吗?
答案 0 :(得分:1)
您的问题来自以下事实:在for
循环之外,您仅生成了一次密码。
您可以在tempFile.write( line.replace( textToSearch, Password ) )
之前生成密码。