在现有字典中添加一个新键:值,然后使用泡菜保存该键,然后在另一个python文件中加载该字典
因此,基本上,我试图创建一个密码管理器,可以保存我的电子邮件和密码。 首先,我创建了一个字典,并使用泡菜:
import pickle
passDB = {} # this is the dictionary
key = input("Email: ") # taking email
password = input("Password: ") # taking password
passDB[key]= password # assigning new email and password into the dictionary
pickle.dump( passDB, open( "passDB.p", "wb" ) ) # saving it as passDB.p
将其保存为add2db.py。然后,我在Python文件中创建了一个密码管理器:
import pickle
passDB = pickle.load( open( "passDB.p", "rb"))
query1 = input("Search your email account to get password: ").lower()
if query1 in passDB.keys():
print(passDB[query1])
else:
print("Nothing such email in database")
将其保存为Passman.py。 因此,这里的问题是,假设我在add2db.py文件中添加了一个新的电子邮件和密码。它添加了完美。当我尝试通过Passman.py文件中的电子邮件搜索密码时,它会完美显示密码。但是同样,当我尝试在Add2db.py中添加另一个电子邮件和密码时,它再次添加了成功,但删除了我首先添加的现有电子邮件和密码。当我尝试使用passman.py查找时,没有第一个电子邮件和密码的迹象 谁能解决以下内容?
- 我想要一个创建add2db.py文件,该文件不断向现有词典添加新的电子邮件和密码。字典必须包含所有以前的电子邮件和密码。这样我就可以在passman.py中查找所有电子邮件和密码
So basically, I am trying to create a password manager where I can save my email and password.
first I created a dictionary and save it using pickle:
import pickle
passDB = {} # this is the dictionary
key = input("Email: ") # taking email
password = input("Password: ") # taking password
passDB[key]= password # assigning new email and password into the dictionary
pickle.dump( passDB, open( "passDB.p", "wb" ) ) # saving it as passDB.p
Saved it as add2db.py. Then I created a password manager in python file like this:
import pickle
passDB = pickle.load( open( "passDB.p", "rb"))
query1 = input("Search your email account to get password: ").lower()
if query1 in passDB.keys():
print(passDB[query1])
else:
print("Nothing such email in database")
Saved it as passman.py.
So, the problem here is, Suppose I added a new email and password into the add2db.py file. It adds perfectly. When I try to search password by email in passman.py file, it shows the password perfectly. But again, when I try to add another email and password in add2db.py, it again adds successfully but removes the existing email and password I added at first. And there is no sign of first email and password when I try to lookup using passman.py
Can anyone solve the following?
- I want a create add2db.py file that keeps adding new email and password to an existing dictionary. The dictionary must contain all previous email and passwords. So that I can look for all the email and password in passman.py
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在add2db.py中,您需要加载数据库,添加新电子邮件,然后再次将其转储。用
passdb = {}
替换passdb = passdb = pickle.load(open(“ passdb.p”,“ rb”)))
。希望这有帮助!In add2db.py, you need to load your database, add the new email, and then dump it again. Replace
passDB = {}
withpassDB = pickle.load( open( "passDB.p", "rb" ) )
. Hope this helps!