尝试在注册登录系统中修复此项

2024-09-30 01:33:45 发布

您现在位置:Python中文网/ 问答频道 /正文

基本上,我正在尝试为我的登录系统创建一个id,出于某种原因,当我将我的id添加到其中时,它似乎只有在我添加它时才起作用。我的目标是让它从0001、0002、0003等开始,但我不知道怎么做。我想在创建用户之前添加id

我尝试过所有不同的方法,比如在代码行中添加int

f.write(create_user + ' : ' + create_pass + "\n")

def register():

    createid = (random.randint(1000, 2000))
    create_user = input("Create your username: ")
    create_pass = input("Create your password: ")
    f = open("users.txt" , "a")
    f.write(create_user + ' : ' + create_pass + "\n")
    f.close

当我把密码

f.write(createid, create_user + ' : ' + create_pass + "\n") 

它在VisualStudio代码中提供

Exception has occurred: TypeError write() takes exactly one argument (2 given) File "D:\Desktop\python\login.py", line 33, in register f.write(createid, create_user + ' : ' + create_pass + "\n") File "D:\Desktop\python\login.py", line 20, in start register() File "D:\Desktop\python\login.py", line 94, in start()


Tags: 代码inpyregisteridinputcreateline
1条回答
网友
1楼 · 发布于 2024-09-30 01:33:45

试试这个

def register():
    createid = random.randint(1000, 2000)
    create_user = input("Create your username: ")
    create_pass = input("Create your password: ")

    with  open("users.txt" , "a") as f:
        f.write("{} : {} : {}\n".format(createid, create_user, create_pass))

相关问题 更多 >

    热门问题