-3
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()

这是一个可以注册用户名和密码的帐户注册器。但是我需要一些帮助......如何让它检查文件中的多行字符串,以及如何让程序在我注册时在文本文件中写入新的字符串而不替换旧字符串?

4

1 回答 1

1

以附加 ( ) 模式打开文件,'a'而不是写入 ( 'w') 以截断文件。

于 2012-05-04T14:41:11.193 回答