保存文件的文本值

save the text value of the file

我有问题。我想在即兴程序中创建一个登录名和密码。如何存储变量的文本值。我问问题不问我我是俄语。一段代码:

import os
print("login:")
logg=input(">")
print("password:")
pasw=input(">")
if logg==rlogg or pasw==rpasw:
  <<body programm>>
else:
  <<body programm>>

我需要将 rlogg 和 rpasw 变量赋值给它们在文件中的值。之后,如果logg和pasw中输入的值等于rlogg和rpasw,则程序继续,否则,程序重新启动。

你的问题不是很清楚,但是这个例子可以帮助你

account.txt >> username:passowrd

Save the username and password in the account.txt file

#To store information in a file
def save(username,password):
    with open("./account.txt","w") as file:
        file.write(f"{username}:{password}")

def login(username,password):
    with open("./account.txt","r") as file:
        user,passwd = file.read().split(":")
        if username==user and password==passwd:
            return True
        return False

print("login:")
logg=input(">")
print("password:")
pasw=input(">")
if login(logg,pasw):
  print("Login successfully")
else:
  print("Failed login")