简体   繁体   English

有没有办法可以保存用户输入然后在 python 中重用它?

[英]is there a way i can save user input then reuse it later in python?

i have this program that asks for their password and i would like to save what the user has inputted into a file then reuse it later.我有一个要求输入密码的程序,我想将用户输入的内容保存到文件中,然后稍后再使用。

while True:
user_input=""

FB=input("What is your Facebook password? \n ")
print("Your Facebook password is " + FB + " is this correct?")

user_input=input()
if user_input == "yes":
    print("password has been saved")
    break
elif user_input == "no":
    print("password was not saved \n")
else:
    print("i do not understand. Sorry")
    break

I wouldn't recommend storing passwords in flat file.我不建议将密码存储在平面文件中。 there are many ways of storing information securely, eg in database.有很多方法可以安全地存储信息,例如在数据库中。 but if you're not concerned with security writing to a text file is very simple:但如果您不关心写入文本文件的安全性,则非常简单:

with open('secret.txt', 'a') as s:
    s.write(FB + '\n')

to know more check the documentation: https://docs.python.org/3/tutorial/inputoutput.html要了解更多信息,请查看文档: https : //docs.python.org/3/tutorial/inputoutput.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM