user = input("\nInput user's Login ID: ")
while True:
password = str(input ("Input user's Password: "))
rpass = str(input("Re-enter the Password: "))
if password == rpass:
file = open("username.txt", "a")
file.write (user)
file.close()
break
else:
print("You have entered the wrong password, Try Again")
我想做一个程序,用户可以注册他们的用户名和密码,它可以存储到一个txt文件。下一个要注册的人将不能使用相同的用户名
我更新了代码,但同样的问题发生了,没有检测到以前的用户名
如果要使用
parse
模块,可以运行pip install parse
并使用以下代码:每次写入文件时,它都会附加到同一行
因此,这种情况永远不会成立
一种可能的解决方案是在每次写入后添加\n
你的情况会是
注意空格和其他字符。它应该与此方法完全匹配
编辑:您正在检查新用户名和密码是否匹配。 您应该做的是将用户与
data.split(':')[0][:-1]
-这将收集字符串直到“:”并截断尾随空间
相关问题 更多 >
编程相关推荐