因此,我正在編寫一個程序,並且我創建了一個將用戶數據存儲在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
@MooningRawr感謝之手 –
不用擔心!只是爲了節省時間,節省時間,節省更多的時間=更多的時間編碼和做其他事情。 – MooingRawr