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
您是否尝试过打印每个字符串的'repr'?我想你会发现,就像口译员告诉你的那样,他们并不平等。 – TigerhawkT3
啊废话,我没有输入()...:P – Kris
我非常感谢你哈哈!文件中的密码包含“\ n”的实例! – Kris