Добрый день, изучаю ООП Python и не могу сообразить почему список в User().notes для всех один и тот же, хотя User().login разный
class User:
def __init__(self, lgn, psw, notes=[]):
self.login = lgn
self.password = psw
self.notes = notes
self.verify = False
def display(self):
for idx, note in enumerate(self.notes, 1):
print(f'{idx}. {note}')
# class Note:
# def __init__(self, text, time=None):
# self.text = text
# self.time = time
class Memory:
def __init__(self):
self.users = []
class Enter:
def enter(self, memory):
while True:
print('1. Войти')
print('2. Зарегистрироваться')
text = input('Выберите нужный пункт меню: ')
if text.strip() == '1':
self.verify(memory)
elif text.strip() == '2':
AddUser().add_user(memory)
else:
print('Неверный пункт меню!')
def verify(self, memory):
while True:
login = input('Логин: ')
for user in memory.users:
if user.login == login.strip():
password = input('Пароль: ')
if user.password == password.strip():
user.verify = True
Menu().menu(user, memory)
else:
print('Неверный пароль!')
print('Такого логина не существует!')
class Menu:
def menu(self, user, memory):
while True:
print('1. Добавить заметку')
print('2. Показать все заметки')
print('3. Выход из профиля')
text = input('Выберите пункт: ')
if text.strip() == '1':
AddNote().add_note(user)
elif text.strip() == '2':
user.display()
elif text.strip() == '3':
user.verify = False
Enter().enter(memory)
break
elif text.strip() == '4':
print(user.login, user.notes)
else:
print('Нет такого пункта!')
class AddNote:
def add_note(self, user):
while True:
text = input('Напишите заметку: ')
if text.strip().lower() == 'стоп':
break
elif text.strip():
user.notes.append(text)
else:
print('Заметка пустая!')
class AddUser:
def add_user(self, memory):
while True:
login = input('Логин: ')
if not login:
continue
password = input('Пароль: ')
if not password:
continue
user = User(login, password)
memory.users.append(user)
user.verify = True
Menu().menu(user, memory)
break
memory = Memory()
a = Enter()
a.enter(memory)