2017-02-20 93 views
1

我正在学习Python,我正在尝试为一个更大的项目制作一个简单的登录程序。相同的字符串不匹配?

此代码:

def _login():#Login Function 
     username = input("Username:\n") 
     password = input("Please enter your password:\n") 
     with open("logins", "r") as log: 
      for line in log: 
      compound = str(username + password) 
      a = line 
      b = str(re.sub(':', '', a)) 
      if a == compound: 
       print("Success") 
_login() searches through a text file where **user:pass** are on individual lines displayed as such in the bold text. 

这就需要你输入用户名和密码的字符串,concats并做同样的与用户名/传文件,免除了“”,这是过滤通过正则表达式。

问题:

将合并的字符串,所述用户输入(VAR 化合物),并从文本文件中的过滤字符串(VAR 一个)不返回真时即使它们都等于用户“UserPass”

我该如何解决这个问题?

Cheers

+0

您是否尝试过打印每个字符串的'repr'?我想你会发现,就像口译员告诉你的那样,他们并不平等。 – TigerhawkT3

+0

啊废话,我没有输入()...:P – Kris

+0

我非常感谢你哈哈!文件中的密码包含“\ n”的实例! – Kris

回答

0

看起来你已经找到了答案。 但我想说,你最好使用'b'来比较而不是'a'。 因为某种原因你应该删除':'。 :)

+0

.........该死的它是repl.it ... Chromebook和Betas!使可读性差。谢谢大声笑 – Kris

相关问题