Hi i get this error: name 'passwords' is not defined when im about to check passwords that i have saved. Why do i get the error?
def login_or_register(self):
user_input = input("Login or Register: ")
if user_input == "login":
self.login2()
elif user_input == "register":
pass
else:
print("Try again!")
self.login_or_register()
def add_password(self):
global sitepassword
global site
Site = input("Enter site name: ")
sitepassword = input("Enter password")
self.add_password_orCheck_password()
global passwords
self.passwords = {Site: sitepassword}
def check_passwords(self):
which_password = input("Which sites password do you want to see?")
for Site in passwords:
if which_password in passwords:
print(sitepassword)
self.add_password_orCheck_password()
def add_password_orCheck_password(self):
add_new = input("Do you want to add a password or check passwords?")
if "add a password" in add_new:
self.add_password()
elif "check passwords" in add_new:
self.check_passwords()
Matt = User("Matterson", "matt@gmail.com", "21.12.1999" ,"male", "Password987")
session1 = Matt.login_or_register()
In check_passwords
, the passwords variable is still local. Yes, you declared it global in another, but you also need to declare it in each function that uses the global variable.
在check_passwords
,变量仍然是局部的,因此在引用变量之前,您需要在每个方法中使用global passwords
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.