import os.path
def start():
if os.path.exists("new.txt") == False:
Account = input('Username: ')
Password_for_account = input('Password: ')
all_the_content = []
all_the_content.append(Account)
all_the_content.append(Password_for_account)
else:
with open("new.txt") as file:
content = file.read()
all_the_content = content.strip('][').split(', ')
while True:
User = input('Username: ')
Password = input('Password: ')
if (User, Password) == all_the_content[0,1] :
print('Done')
break
else:
print('Invalid Password')
continue
return 'You have been succesfully logged in!'
print(start())
with open("new.txt") as file:
content = file.read()
all_the_content = content.strip('][').split(', ')
def add_new_pass():
new_username = input('Enter the new username: ')
new_password = input('Enter the new password: ')
all_the_content.append(new_username)
all_the_content.append(new_password)
return 'Your password has been added'
def check_pass(username):
position = all_the_content.index(username)
if username in all_the_content and position%2 == 0:
return 'The password for '+ username, 'is '+ all_the_content[position + 1]
else:
return 'Invalid username'
print(add_new_pass())
a = input()
print(check_pass(a))
with open ('new.txt', 'w') as file:
file.write(str(all_the_content))我是个初学者。这段代码做了所有的事情,除了一件事,每次我把文件设为"new.txt“的时候。如有任何帮助,我们不胜感激!它将其存储为"new2.txt“。我用的是Jupyter笔记本。
发布于 2020-10-08 10:02:56
你已经在那个文件夹中有了一个new.txt,这就是为什么它将这个命名为new2.txt,删除或重命名第一个,然后尝试重新运行你的程序。
发布于 2020-10-08 10:55:34
您没有在正确的目录中查找,或者该目录已有同名的现有文件。还要检查您对该目录的写访问权限
https://stackoverflow.com/questions/64254672
复制相似问题