如何将多个用户输入添加到文本文件?

时间:2018-07-11 04:24:23

标签: python text

我试图弄清楚如何列出用户输入内容而不覆盖先前输入的文本,而是无限地添加更多内容。

到目前为止,这是我的代码:

def main():

    domain=input('Enter domain: ')
    email=input('Enter your email or username: ')
    password=input('Enter your password: ')



    text_file = open("Data.txt", "w")

    text_file.write("Domain of login: "+domain+'\n'+"Email/username: 
    "+email+'\n'+"Password: "+password)
    text_file=open("Data.txt", "r")
    text = text_file.read()
    print(text)
    text_file.close()

main()

这是输出示例:

Domain of login: Facebook.com
Email/username: 1234567@email.com
Password: pas5word

这是我要针对的概念:

Domain of login: Facebook.com
Email/username: 1234567@email.com
Password: pas5word

Domain of login: Youtube.com
Email/username: 1234567@email.com
Password: pas5word2

Domain of login: Twitter.com
Email/username: 54321@email.com
Password: pas5word3

0 个答案:

没有答案