ALI MANSOOR ALI MANSOOR - 1 year ago 103
Python Question

How to store user input in txt file?(Python 3)

So i am writing a program and i made a function which stores user data in a txt file.It is like a simple registration function.The user gives the username and password to store.Problem is i can't store user input in the file.

My code is :

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.")

So what i get is two text files user and pass but they are empty.
What am i doing wrong??
and please do not tell me to use modules for registraion.

Regards ali7112001

Answer Source

You didn't fwu.close() or fwp.close() (you didn't save it). Also a quick look up next time would save you some time. .write not working in Python

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download