0

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

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

0

2 Answers 2

1

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

2
  • @MooningRawr thanks man Commented Sep 12, 2016 at 14:22
  • No worries! Just trying to save you time, save people time, more time saved = more time coding and doing other things.
    – MooingRawr
    Commented Sep 12, 2016 at 14:23
0

Please try with raw_input() instead of input()

Also please close() the files.

Not the answer you're looking for? Browse other questions tagged or ask your own question.