errorHudFrameLayout
获取:
import sys
users = {}
status = ""
f = open("password.txt", "r")
while status != "q":
status = input("Are you a registered user? y/n? Press q to quit: ")
if status == "n":
createLogin = input("Create login name: ")
if createLogin in users:
print("Login name already exist!\n")
else:
createPassw = input("Create password: ")
users[createPassw] = createPassw
print("\nUser created!\n")
f.write(createLogin)
f.write(createPassw)
elif status == "y":
login = input("Enter login name: ")
if login in users:
passw = input("Enter password: ")
print
if login in users and passw in users:
print("Login successful!\n")
else:
print
print("User doesn't exist!\n")
为什么这不能让我将用户名或密码写入外部文件。
plz您可以帮助修复我的代码还是编写更好的版本plz。
我希望该代码成为基本的帐户检查者,然后在该人没有帐户的情况下进行注册。
答案 0 :(得分:1)
为open()
函数添加读写模式:
f = open("password.txt", "r+")
file_object =打开(“文件名”,“模式”)
模式为:
参考: https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files