Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
混合使用2个Python文件_Python_Python 2.7 - Fatal编程技术网

混合使用2个Python文件

混合使用2个Python文件,python,python-2.7,Python,Python 2.7,嘿,我现在正在做一个小工具只是为了好玩。它可以获取用户名和密码列表,并打印出所有可能的组合 Python 2.7 我的代码 while True: cnt = 1 cntpw = 1 currentusernameopen = open((usernamelist), "r") linesim = currentusernameopen.read().split("\n") usernameused = (linesim[cnt]) whi

嘿,我现在正在做一个小工具只是为了好玩。它可以获取用户名和密码列表,并打印出所有可能的组合

Python 2.7

我的代码

    while True:
    cnt = 1
    cntpw = 1
    currentusernameopen = open((usernamelist), "r")
    linesim = currentusernameopen.read().split("\n")
    usernameused = (linesim[cnt])
    while True:
        try:
            currentpassopen = open((passwordlist), "r")
            linesimpw = currentpassopen.read().split("\n")
            pwused = (linesimpw[cntpw])
            print usernameused+":"+pwused
            cntpw += 1
        except:
            cnt += 1
但当它到达passowrds的末尾时,它只打印: 用户1: 停下来

您不应该使用异常来控制正常的程序流 您应该为变量使用有意义的名称,并使用下划线分隔单词 您只需对文件进行迭代,无需全部读取然后拆分 而且也没有必要保持这样的计数器 编辑:我对此类活动的建议:

#!/usr/bin/env python3
users = open("users", "r")
passwords = open("passwords", "r")
for user in users:
    for password in passwords:
        print("%s: %s" % (user.strip(), password.strip()))
    passwords.seek(0)

strip删除所有尾随的空格,这里是最后一个\n

如果这是您的意思,那么pwused typepwdusedString是什么类型