[英]When i try to make python write user input to a txt file, it doesn't
i am learning python, and i wanted to create a little login and register program, that writes the username and the password to a txt file (so that it can be later used), i am currently working on the register function, when i try to write to the txt files it does nothing, i tried doing a with loop, a.flush() and.close() but neither of them saves the info.我正在学习 python,我想创建一个小登录和注册程序,将用户名和密码写入 txt 文件(以便以后使用),我目前正在注册 function,当我尝试要写入 txt 文件,它什么也不做,我尝试使用循环、a.flush() 和 .close(),但它们都没有保存信息。 Here's my code:
这是我的代码:
username.write = input ('username > ')
password = open("password.txt", "w")
password.write = input ('password > ')
print('Welcome.')
username.close()
password.close()
What am i missing?我错过了什么? Edit.
编辑。 Neither 3 of the solutions to the suggested question work for me...
建议问题的三个解决方案都不适合我......
Get your input and store them in two variables and then write them to files:获取您的输入并将它们存储在两个变量中,然后将它们写入文件:
username = input ('username > ')
password = input ('password > ')
with open('usernames.txt', 'w') as userFile:
userFile.write(username)
with open('passwords.txt', 'w') as passFile:
passFile.write(password)
yourfile.open(filename,'w')
username = input()
password = input()
yourfile.write(username)
yourfile.write(password)
yourfile.close()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.