2013-07-25 2 views
-5

두 개의 txt 파일에서 사용자 이름과 암호를 가져 오는 스크립트가 있습니다. 내 문제는 각 사용자에게 목록의 모든 암호를 시도하도록 지정하는 방법입니다. 내 스크립트는 지금까지 이와 같이 보입니다.사용자에게 여러 암호를 할당하는 방법

[email protected] Password1 
[email protected] Password2 
[email protected] Password3 
[email protected] Password4 
[email protected] Password5 
[email protected] Password6 
[email protected] Password7 
[email protected] Password8 
[email protected] Password9 
[email protected] Password10 

이 내가 실현하려 노력하고 무엇 :

user = open ('users.txt' , 'r') 
password = open ('password.txt' , 'r') 

for file1, file2 in zip (user, password): 
    print ('{0}\t{1}'.format(file1.strip(), file2.strip())) 

내가 내 출력을 위해 무엇을 얻을

[email protected] "Password1 
        Password2 
        Password3 
        Password4 
        Password5 
        Password6 
        Password7 
        Password8 
        Password9 
        Password10" 

[email protected] "Password1 
        Password2 
        Password3 
        Password4 
        Password5 
        Password6 
        Password7 
        Password8 
        Password9 
        Password10" 

을 그리고 돌아갑니다 사용자 2를 얻고 10 개의 암호를 가져옵니다 .

+5

'어떻게 각 사용자에게 모든 암호를 시도하도록 할 수 있습니까? ' 적절한 영어로 이것은 정확히 무엇을 의미합니까? –

+0

[email protected]에서 10 개의 암호를 모두 사용하려면 어떻게합니까? 그런 다음 작업이 완료되면 다음 사용자 2에게 가서 마지막 사용자까지 10 개의 암호를 모두 사용합니다. –

답변

1

각 사용자에게 모든 비밀번호를 알려주 길 원한다면 무엇을 의미하는지 모르겠습니다. 모든 암호를 한 줄에 입력하고 사용자를 반복 한 다음 해당 줄을 추가하십시오. 같은

뭔가 : 여기

lineWithAllPasswords = ','.join(password,'\n') 

for user in users: 
    print (user + '\t' + lineWithAllPasswords) 
+0

나를 올바른 방향으로 안내해 주셔서 감사합니다. –

0

위의 질문에 대한 솔루션입니다. 각 사용자는 password.txt 파일을 반복합니다.

user = open ('users.txt' , 'r') 
password = open ('password.txt' , 'r') 
pa = '\n'.join(password) 

for users in user: 
    print pa + users 
관련 문제