2016-09-12 59 views
0

因此,我正在编写一个程序,并且我创建了一个将用户数据存储在txt文件中的函数。它就像一个简单的注册函数。用户给出用户名和密码存储。问题是我无法将用户输入存储在文件中。如何在txt文件中存储用户输入?(Python 3)

我的代码是:

def reguser():  #Function name. 

    fwu = open('user.txt','w')  #create or open user.txt file. 
    user = input("Username: ")  #takes the user input.e.g what username to register 
    fwu.write(user)    #this command should write input into the file 
    fwp = open('pass.txt','w')  #create or open pass.txt file. 
    pas = input ("Password: ") #takes user input e.g what password to register 
    fwp.write(pas)     #write the password into the file 
    print ("To check for registraion completion, please login.") 
    askuser()  

所以我得到的是两个文本文件的用户,并通过但都是空的。 我在做什么错? ,请不要告诉我使用注册模块。

问候ali7112001

回答

1

你没有fwu.close()fwp.close()(你没救了的话)。下次快速查找会为您节省一些时间。 .write not working in Python

+0

@MooningRawr感谢之手 –

+0

不用担心!只是为了节省时间,节省时间,节省更多的时间=更多的时间编码和做其他事情。 – MooingRawr

0

raw_input()代替输入()

尝试还请close()的文件。

相关问题