简体   繁体   中英

File creation with python for users and passwords

I am making a user creation and login system, but when I create the user there isn't any content in the related file.

inp = "newuser bob password"   
if inp.startswith("newuser "):
            file = open(f".{inp.split(' ')[1] }.txt", "x")
            file.close()
            file = open(f".{inp.split(' ')[1] }.txt", "w")
            file.write(str(inp.split(' ')[2]))

The script runs without any problems or errors the file gets created and but it doesn't contain anything.

Closing the file writes any changes. So, you should again add a close method to the end. Code:

inp = "newuser bob password"   
if inp.startswith("newuser "):
            file = open(f".{inp.split(' ')[1] }.txt", "w")
            file.write(str(inp.split(' ')[2]))
            file.close()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM