为什么我的代码不读这行?

时间:2018-02-22 21:56:48

标签: python debugging sftp

所以我创建了一个程序,用来从SFTP服务器读取带有密码的用户名(盐渍和散列),用户可以安全登录。用户也可以创建自己的帐户,但我在检查用户名是否已存在时遇到问题。我已经设法正确地编写了代码,但由于一些奇怪的原因,我无法找出为什么我的代码不会读取for for循环,至少它没有打印" debug& #34;字符串,例如下面。任何帮助将不胜感激!

def createUser():
f = ftp.open("paroolid.txt", "a+")
passListDecode = f.read().decode("UTF-8")
passList = passListDecode.splitlines()
newName = input("Uus kasutajanimi: ")
if len(newName) <= 0:
    print("Nimi peab olema vähemalt 1 täht!")
    createUser()
#This is the loop that won't be read
for line in passList:
    print("debug")
    pp = ""
    pp += line.split(",")[1].strip().split("-")[0].strip()
    pp += newName
    userInFile = hashlib.md5(pp.strip().encode()).hexdigest()
    if userInFile == line.split(":")[0].strip():
        print("Nimi juba olemas!")
        createUser()
#But this line is read successfully, like the above for loop is just being skipped.
newPass = getpass.getpass("Uus parool: ")

1 个答案:

答案 0 :(得分:1)

每个人,我都修好了。 我了解到当你使用&#34; a +&#34;时,你不能使用read()函数。打开文件时,您需要使用seek(0)。 有了这个问题就得到了回答,感谢Mike Scotty建议列表可能是空的,我之前没想过。