下面的代码没有错误或问题我想将此脚本“连接”到外部文件或数据库,以便在脚本执行后可以存储和使用“我的字典”的内容。我正在寻找如何实现这一点的想法。我不是要求修复代码,因为它是功能性的。它只是提供上下文。你知道吗
my_dict = {}
class password(object):
def __init__(self):
pass
def username_input(self):
self.user = str(input("Please enter the username you would like to use: "))
return self.user
#gets the input for a username
def password_input(self):
self.passw = str(input("Please enter the password you would like to use: "))
return self.passw
#gets the input for a password
def username_creator(self):
password.username_input(self)
return self.user
def password_creator(self):
password.password_input(self)
return self.passw
def swap_username(self, new_pass, old_pass):
my_dict[new_pass] = my_dict.pop(old_pass)
def swap_password(self, new_pas, old_pas):
my_dict[old_pas] = new_pas
def username_change(self):
self.d = input("please enter your username: ")
for key in my_dict:
if key == self.d:
self.x = input("enter a new username: ")
password().swap_username(self.x, self.d)
print("your username has been updated!")
break
else:
print("the username you entered does not exist in our records")
password().username_change()
def password_change(self):
self.e = input("please enter your username: ")
self.q = input("please enter your password: ")
for key, value in my_dict.items():
if key == self.e and value == self.q:
self.z = input("enter a new password: ")
password().swap_password(self.z, self.e)
break
else:
print ('the combination entered does not exist in our records')
password().password_change()
make_a_username = password()
my_dict.update({(make_a_username.username_creator()): (make_a_username.password_creator())})
实现这一点的一种方法是将
my_dict
存储在文件中。所以基本上,每次启动应用程序时,都要从文件中加载my_dict
,然后在关闭之前,将更新的my_dict
再次存储到文件中。因为它是一个字典,所以可以将它存储在JSON中。你知道吗所以,你最终要做的是:
相关问题 更多 >
编程相关推荐