def info(): #Here you can write your password and username.
Username = raw_input ("Username: ")
Password = raw_input ("Password: ")
print("")
for line in open('/home/hello/Usernames.txt'):
if Username == Username in line: #Checks if username is available.
print ("Username is already taken!\n")
info()
else:
User = open("/home/hello/Usernames.txt", "w") #Registers username.
User.write(Username)
Psw = open("/home/hello/Passwords.txt", "w") #Registers password.
Psw.write(Password)
print ("You have succsesfully registered!") #If you managed to register.
break
info()
这是一个帐户注册人,可以注册用户名和密码。但是我需要一些帮助...如何让它检查文件中的多行字符串,如何在注册时使程序在文本文件中写入一行新的字符串而不替换旧的字符串? / p>
答案 0 :(得分:1)
打开文件以追加('a'
)模式,而不是写入('w'
)截断文件。