我变成了这个错误:
回溯(最近一次呼叫):
文件“xx”,第51行,in
Kontrolle.CheckSign()
文件“xx”,第46行,勾号
if self.isSigned == True:
AttributeError:“Sicherheit”对象没有属性“isSigned”
你能帮我吗?你知道吗
import hashlib
class Sicherheit:
passwordFile = 'usercreds.tmp'
def Signup(self):
self.isSigned = False # !!! self.isSigned
print("Sie müssen sich erst anmelden!\n")
usernameInput = input("Bitte geben Sie Ihren Nutzername ein: \n")
passwordInput = input("Bitte geben Sie Ihr Passwort ein: \n")
usernameInputHashed = hashlib.sha512(usernameInput.encode())
passwordInputHashed = hashlib.sha512(passwordInput.encode())
with open(self.passwordFile, 'w') as f:
f.write(str(usernameInputHashed.hexdigest()))
f.write('\n')
f.write(str(passwordInputHashed.hexdigest()))
f.close()
self.isSigned = True # !!! self.isSigned
print("Anmeldung war erfolgreich!\n")
print("======================================================\n")
self.Login() # Moves onto the login def
def Login(self):
print("Sie müssen sich einloggen!\n")
usernameEntry = input("Bitte geben Sie Ihren Nutzername ein: \n")
passwordEntry = input("Bitte geben Sie Ihr Passwort ein: \n")
usernameEntry = hashlib.sha512(usernameEntry.encode())
passwordEntry = hashlib.sha512(passwordEntry.encode())
usernameEntryHashed = usernameEntry.hexdigest()
passwordEntryHashed = passwordEntry.hexdigest()
with open(self.passwordFile) as r:
info = r.readlines()
usernameInFile = info[0].rstrip()
passwordInFile = info[1].rstrip()
if usernameEntryHashed == usernameInFile and passwordEntryHashed == passwordInFile:
print("Anmeldung war erfolgreich!\n")
else:
print("Anmeldung war nicht erfolgreich!!!\n")
self.Login()
def CheckSign(self):
if self.isSigned == True: # !!! self.isSigned
self.Login()
else:
self.Signup()
Kontrolle = Sicherheit()
Kontrolle.CheckSign()
移动线路
从
SignUp
方法进入类变量,或者为类创建一个__init__
方法并在其中初始化它当你打电话时:
设置变量
self.isSigned
的代码从未执行过(它是SignUp
方法的一部分,因此在调用时:它查找尚未设置的变量,然后抛出错误:
下面是如何在类中声明它:
相关问题 更多 >
编程相关推荐