type object 'SQLighter' has no attribute 'connection
При вызове функции SQLighter.output_users() выводит эту ошибку: type object 'SQLighter' has no attribute 'connection', хотя в __init__ задана переменная self.connection. Подскажите в чем проблема или может я чего-то не замечаю. И еще вопрос я все правильно делаю, чтобы из функции output_users сработала функция iter_row?
Код:
import mysql.connector
from read_sql_config import read_db_config
class SQLighter:
def __init__(self):
"""Подключаемся к БД и сохраняем курсор соединения"""
self.db_config = read_db_config()
self.connection = mysql.connector.connect(**self.db_config)
self.cursor = self.connection.cursor(buffered=True)
def iter_row(self, cursor, size=10):
while True:
rows = cursor.fetchmany(size)
if not rows:
break
for row in rows:
yield row
@classmethod
def output_users(self):
"""Вывод всех пользователей"""
with self.connection:
self.cursor.execute(
"SELECT * FROM users")
return self.iter_row(self.cursor, 10)
SQLighter.output_users()