0
我成爲了這個錯誤:(類,閃避,個體經營)AttributeError的: 'XX' 對象有沒有屬性 'XX'
回溯(最近通話最後一個):
文件 「XX」,行51在
Kontrolle.CheckSign()
文件 「XX」,46行,在CheckSign
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()
我怎麼能初始化它在那裏? –