我正在尝试制作一个保存密码的程序。如何获取输入并将其放入文本文件password.txt?我将来如何检索这些数据并将其打印出来
def display():
print ("Do you want to add a password to get a password? get/add")
response = input()
if response == "get":
savingPasswords()
def savingPasswords():
username = input("Enter username")
username = open ('password.txt', 'w')
password = input ("Enter password")
account = input("What account is this for?")
print ("Login successfully saved!")
while status == True:
display()
您可以将数据存储为json:
写入文件:
要从文件中读取密码,请尝试:
问题在于您的第二个函数。我建议使用with open来打开和写入文件,因为它看起来更干净,更易于阅读。在代码中,您从未写入文件或关闭文件。with open方法在执行缩进块后为您关闭文件。我还建议将类似csv文件的内容写入此类有组织的信息中,以便以后更容易检索
相关问题 更多 >
编程相关推荐