【问题标题】:save the text value of the file [closed]保存文件的文本值[关闭]
【发布时间】:2021-04-25 15:01:28
【问题描述】:

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

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,那么程序继续,如果不是,则程序重新启动。

【问题讨论】:

标签: python save


【解决方案1】:

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

account.txt >> username:passowrd

将用户名和密码保存在account.txt文件中

#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")

【讨论】:

    猜你喜欢
    • 2016-12-20
    • 1970-01-01
    • 2014-04-04
    • 2013-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-07
    相关资源
    最近更新 更多