它可以看到文件,如果我稍微更改路径上的名称,运行seizes即可运行,但无论如何,它都无法读取文件中的单词,尽管我以前在编写程序时可以读取。现在它突然不起作用了,文件位置是一样的
附言:我不知道如何在溢出上指定代码
filen = 'C:UsersfabbyDocumentsExtra Things I Might NeedPort Folio StuffPythonusernames'
usern = open(filen, 'r')
userr = input("Enter your Username: ")
ass = input("Enter your Password: ")
def func():
user = input("Enter new Username: ")
passs = input("Enter new Password: ")
passs1 = input("Confirm password: ")
if passs != passs1:
print("Passwords do not match!")
else:
if len(passs) <= 6:
print("Your password is too short, restart:")
elif user in usern:
print("This username already exists")
else:
usern = open(filen, "a")
usern.write(user+", "+passs+"n")
print("Success!")
while True:
if userr not in usern:
again = input("This username does not exist, would you like to try again? ")
if again == ("No"):
func()
elif again == ("no"):
func()
elif again == ("Yes"):
print("Try again:")
userr = input("Enter your Username: ")
ass = input("Enter your Password: ")
elif again == ("yes"):
print("Try again:")
userr = input("Enter your Username: ")
ass = input("Enter your Password: ")
elif userr in usern:
print("Good, you have entered the zone")
我不确定我是否完全理解你的方法,但作为你的代码,我有一些建议:
-
如果打开,请关闭文件
-
使用f.readline((和str.split((解析用户名和密码并存储在数组中,因此如果文件不是很大,可以使用in进行检查。